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

MeanGrayLevel-on-ROIs

by AMAR

This script, measures the Mean Intensity in each ROIs in a GrayScale.
you Must Open a picture file, select your ROIs, save your ROIs File, and launch the Script MeanGrayLevel-on-ROIs.
you have in the end a Excel File with the Surface and the MeanGrayLevel by ROIs.

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.image.lut.LUT)
importClass(Packages.icy.gui.dialog.MessageDialog)
importClass(Packages.icy.file.Loader)
importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog)
importClass(Packages.java.awt.image.BufferedImage)
importClass(Packages.icy.sequence.SequenceUtil)
importClass(Packages.icy.util.XLSUtil)
importClass(Packages.icy.roi.ROIUtil)

sequence = getSequence()

if (sequence == null) {
	file = FileDialog.open()

	if (file == null) {
		MessageDialog.showDialog("Cannot go further without an image to process")
		throw "User cancelled"
	}

	sequence = Loader.loadSequence(file)
}

fileName = sequence.getFilename()
dot = fileName.lastIndexOf(".")
fileName = fileName.substring(0, dot) + "_MeanGrayLevel.xls"

xls = XLSUtil.createWorkbook(fileName)
sheet = XLSUtil.createNewPage(xls, "Mean gray level")
XLSUtil.setCellString(sheet, 0, 1, "Surface (px)")
XLSUtil.setCellString(sheet, 0, 2, "Mean gray level")

// Retrieve the ROI from the sequence
rois = sequence.getROI2Ds(true)

// Convert the sequence to gray scale
// BufferedImage.TYPE_BYTE_GRAY = 10
sequence = SequenceUtil.convertColor(sequence, 10, null)

// Calculate the (inverted) mean intensity per ROI
for (i = 0; i < rois.size(); i++) {
	roi = rois.get(i)
	info = ROIUtil.getIntensityInfo(sequence, roi)

	mod = 1 - (info.meanIntensity / 255)

	XLSUtil.setCellString(sheet, i + 1, 0, roi.getName())
	XLSUtil.setCellNumber(sheet, i + 1, 1, roi.getNumberOfPoints())
	XLSUtil.setCellNumber(sheet, i + 1, 2, mod)
}
xls.write()
xls.close()

MessageDialog.showDialog("Data has been saved to " + fileName)

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



Icy script publication Id : P5G4U4