Need help or advice ? Come to the Icy club ! - Every Wenesday morning from 9h30 to 12h30 - Francois Jacob Building - Main hall - Pasteur
Register

Pixels XLS export per channel

by stef / Stephane Dallongeville

This script allow you to export all pixels values which are contained in ROI(s) into a excel file.
Process is done so channel are separated in different sheet and pixels are grouped per ROI.

version 1 (last version):

download to use and modify in Icy. How do I use scripts ? A Problem ? ask the community.
Changelog for this version: initial version
importClass(Packages.icy.gui.dialog.MessageDialog)
importClass(Packages.icy.gui.frame.progress.ProgressFrame)
importClass(Packages.icy.file.FileUtil)
importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog)
importClass(Packages.icy.util.XLSUtil)
importClass(Packages.icy.util.XMLUtil)
importClass(Packages.icy.util.ShapeUtil)
importClass(Packages.icy.roi.ROIUtil)
importClass(Packages.icy.sequence.SequenceDataIterator)

// get active sequence
s = getSequence()

if (s == null)
{
	MessageDialog.showDialog("You should open an image first")
	exit
}

// get sequence ROIs
rois = s.getROIs()

if (rois.size() > 0)
{
	// request path to save XLS result
	path = FileDialog.open()

	if (path != null)
	{
		// display progress frame
		p = new ProgressFrame("exporting...")
		
		// set XLS extension
		path = FileUtil.setExtension(path, ".xls")

		//create a new excel document
		wb = XLSUtil.createWorkbook(path)

		for(c = 0; c < s.getSizeC(); c++)
		{
			sh = XLSUtil.createNewPage(wb, "Pixels - " + s.getChannelName(c))
			line = 0

			for(i = 0; i < rois.size(); i++)
			{
				// get current roi
				r = rois.get(i)
				// create an iterator through the given sequence and ROI
				it = new SequenceDataIterator(s, r, false, -1, -1, c)

				XLSUtil.setCellString(sh, 0, line, r.getName())
				XLSUtil.setCellNumber(sh, 1, line, i)
				XLSUtil.setCellString(sh, 3, line, "Number of pixel =")
				XLSUtil.setCellNumber(sh, 4, line, Math.floor(r.getNumberOfPoints()))
				line += 2

				// set column titles
				XLSUtil.setCellString(sh, 0, line, "X")
				XLSUtil.setCellString(sh, 1, line, "Y")
				XLSUtil.setCellString(sh, 2, line, "Z")
				XLSUtil.setCellString(sh, 3, line, "T")
				XLSUtil.setCellString(sh, 4, line, "Value")
				line++				
						
				while(!it.done())
				{
					// set position information
					XLSUtil.setCellNumber(sh, 0, line, it.getPositionX())
					XLSUtil.setCellNumber(sh, 1, line, it.getPositionY())
					XLSUtil.setCellNumber(sh, 2, line, it.getPositionZ())
					XLSUtil.setCellNumber(sh, 3, line, it.getPositionT())
					// set value
					XLSUtil.setCellNumber(sh, 4, line, it.get())
		
					// pass to next value
					it.next()
					line++
				}

				line++
			}
		}

		// save and close excel document
		XLSUtil.saveAndClose(wb)

		// done
		p.close()
	}
}
else MessageDialog.showDialog("You should have at least 1 ROI in your image")

This script has no documentation. A Problem ? ask the community.



Icy script publication Id : N2X9N8