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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980importClass(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 sequenceseq = getSequence()// get channel of interestch0 = SequenceUtil.extractChannel(seq, 0)// gaussian filtersigma = 3kernelX = 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 thresholdingkmeans = KMeans.computeKMeansThresholds(ch0, 2)// performs the threshold and put the result (a sequence) inside a variableresult = Thresholder.threshold(ch0, 0, kmeans, false)// get connected components as ROIsrois = 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 pagepage = XLSUtil.createNewPage( workbook, "my result page")// create table headercol = 0for(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 sequenceseq.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 channelspos = roi.getPosition5D()pos.setC(-1)roi.setPosition5D(pos)// add result ROI to original sequenceseq.addROI(roi)col = 0for(c = 0; c < seq.getSizeC(); c++){// compute min, mean and max intensityminIntensity = 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)