Script

Excel export of mean intensity and standard deviation for an images folder

Publication ID: ICY-O2Y9Y4

Short Description

This script compute and exports the mean intensity and the standard deviation for a complete folder of image into a single excel file. If the image contains a region of interest the script uses it to localize the mean intensity and standard deviation calculation.

Versions

  • Version 1 • Released on: 2014-10-23 14:31:09
    Download
    Description:

    initial version

    importClass(Packages.icy.roi.ROI2DRectangle)
    importClass(Packages.icy.roi.ROIUtil)
    importClass(Packages.icy.sequence.Sequence)
    importClass(Packages.icy.util.XLSUtil)
    importClass(Packages.icy.file.Loader)
    importClass(Packages.icy.file.FileUtil)
    importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog)
    importClass(Packages.plugins.tprovoost.scripteditor.uitools.userdialogs.Dialog)
    
    // select input folder
    inputFolder = FileDialog.openFolder()
    // cancelled
    if (inputFolder == null) throw "Cancelled..."
    
    // create output file name for XLS file
    xlsFileName = inputFolder.getAbsolutePath() + "/result.xls"
    // create excel document
    wb = XLSUtil.createWorkbook(xlsFileName)
    // create a new page in the excel document
    ws = XLSUtil.createNewPage(wb, "result")
    
    // set excel headers
    XLSUtil.setCellString(ws, 0, 0, "filename")
    XLSUtil.setCellString(ws, 2, 0, "average")
    XLSUtil.setCellString(ws, 3, 0, "st dev")
    
    // get all files from input folder
    files = FileUtil.getFiles(inputFolder, null, false, false, false)
    
    for(i = 0; i < files.length; i++)
    {
    	// get current file
    	f = files[i]
    	// load image
    	seq = Loader.loadSequence(f.getAbsolutePath(), 0, false)
    
    	if (seq != null)
    	{
    		// get image rois 
    		rois = seq.getROIs()
    		// we only take the first roi
    		if (rois.size() > 0) roi = rois.get(0)
    		// use the whole sequence as rectangular ROI
    		else roi = new ROI2DRectangle(seq.getBounds2D())
    	
    		// compute the mean intensity for the whole roi
    		// be careful, if the image has severals channels
    		mean = ROIUtil.getMeanIntensity(seq, roi)
    		// compute the standard deviation for the whole roi
    		// be careful, if the image has severals channels
    		stdev = ROIUtil.getStandardDeviation(seq, roi)
    	
    		// write results in excel file
    		XLSUtil.setCellString(ws, 0, i + 1, f.getAbsolutePath())
    		XLSUtil.setCellNumber(ws, 2, i + 1, mean)
    		XLSUtil.setCellNumber(ws, 3, i + 1, stdev)
    	}
    }
    
    // close and save the excel file
    XLSUtil.saveAndClose(wb)
    

Leave a Review