Script

MeanGrayLevel-on-ROIs

Publication ID: ICY-P5G4U4

Short Description

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.

Versions

  • Version 1 • Released on: 2014-09-25 11:45:44
    Download
    Description:

    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)
    

Leave a Review