Short Description
Here is what this script does from an input image: - apply a gaussian filter to improve the segmentation - do KMeans threshold - extract connected component as ROI - export ROI intensities values in a excel file.Versions
-
Version 1 • Released on: 2015-01-12 16:51:43DownloadDescription:
initial version
importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog) importClass(Packages.icy.roi.ROIUtil) importClass(Packages.icy.util.XLSUtil) importClass(Packages.plugins.adufour.roi.LabelExtractor) importClass(Packages.plugins.adufour.thresholder.KMeans) importClass(Packages.plugins.adufour.thresholder.Thresholder) importClass(Packages.icy.sequence.SequenceUtil) importClass(Packages.plugins.adufour.filtering.Convolution1D) importClass(Packages.plugins.adufour.filtering.Kernels1D) importClass(java.lang.Double) // get current active sequence seq = getSequence() // get channel of interest ch0 = SequenceUtil.extractChannel(seq, 0) // gaussian filter sigma = 3 kernelX = Kernels1D.CUSTOM_GAUSSIAN.createGaussianKernel1D(sigma).getData() kernelY = Kernels1D.CUSTOM_GAUSSIAN.createGaussianKernel1D(sigma).getData() Convolution1D.convolve(ch0, kernelX, kernelY, null); // computes the kmeans thresholds for automatic thresholding kmeans = KMeans.computeKMeansThresholds(ch0, 2) // performs the threshold and put the result (a sequence) inside a variable result = Thresholder.threshold(ch0, 0, kmeans, false) // get connected components as ROIs rois = LabelExtractor.extractLabels(result, LabelExtractor.ExtractionType.ALL_LABELS_VS_BACKGROUND, 0) // create excel file (ask user for output file) workbook = XLSUtil.createWorkbook(FileDialog.open()) // create excel page page = XLSUtil.createNewPage( workbook, "my result page") // create table header col = 0 for(c = 0; c < seq.getSizeC(); c++) { XLSUtil.setCellString(page, col++, 0, "min intensity ch" + c) XLSUtil.setCellString(page, col++, 0, "mean intensity ch" + c) XLSUtil.setCellString(page, col++, 0, "max intensity ch" + c) } seq.beginUpdate() // remove all ROIS from the active sequence seq.removeAllROI() for(i = 0; i < rois.size(); i++) { roi = rois.get(i) // change C position to -1 (all channel) in order to retrieve stats for all channels pos = roi.getPosition5D() pos.setC(-1) roi.setPosition5D(pos) // add result ROI to original sequence seq.addROI(roi) col = 0 for(c = 0; c < seq.getSizeC(); c++) { // compute min, mean and max intensity minIntensity = ROIUtil.getMinIntensity(seq, roi, -1, -1, c) meanIntensity = ROIUtil.getMeanIntensity(seq, roi, -1, -1, c) maxIntensity = ROIUtil.getMaxIntensity(seq, roi, -1, -1, c) XLSUtil.setCellNumber(page, col++, i+1, minIntensity) XLSUtil.setCellNumber(page, col++, i+1, meanIntensity) XLSUtil.setCellNumber(page, col++, i+1, maxIntensity) } } seq.endUpdate() XLSUtil.saveAndClose(workbook)