Short Description
Performs a binary threshold using KMeans on an image smoothened with a Gaussian filter (kernel 3x3). Similar to the protocol tutorial (without ROIs)Versions
-
Version 2 • Released on: 2015-07-21 06:07:20DownloadDescription:
Added documentation
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061/*import the different Classes needed- FileDialog is used to select file and Loader to load the image- Package filtering is used to create the kernel and perform the convolution- Package thresholder is needed to do the threshold withThresholder and KMeans classes.*/importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog)importClass(Packages.icy.file.Loader)importClass(Packages.plugins.adufour.filtering.Convolution1D)importClass(Packages.plugins.adufour.filtering.Kernels1D)importClass(Packages.plugins.adufour.thresholder.Thresholder)importClass(Packages.plugins.adufour.thresholder.KMeans)importClass(Packages.icy.file.Saver)/** Request image file and verify if path is not empty*/f = FileDialog.open()if (!f.toString().equals("")) {/** Load sequence from f and check if seq is valid*/seq = Loader.loadSequence(f, 0, true)if (seq != null) {/** Set the kernel of 3x3*/sigma = 3kernelX = Kernels1D.CUSTOM_GAUSSIAN.createGaussianKernel1D(sigma).getData()kernelY = Kernels1D.CUSTOM_GAUSSIAN.createGaussianKernel1D(sigma).getData()/** Create a copy of the original sequence and perform convolution*/seqf = seq.getCopy()Convolution1D.convolve(seqf, kernelX, kernelY, null)/** Show gaussian result*/gui.addSequence(seqf)/** Find threshold using KMeans method and perform binary threshold*/kmeans = KMeans.computeKMeansThresholds(seq, 2, 2, 255)result = Thresholder.threshold(seqf, 2, kmeans, false)result.setName(seq.getName() + " - thresholded")/** Show result of binary Threshold*/gui.addSequence(result)/** Save result to file*///f = FileDialog.save()//Saver.save(result, f, true, true)}} -
Version 1 • Released on: 2015-07-21 05:48:57DownloadDescription:
initial version
123456789101112131415161718192021222324252627importClass(Packages.plugins.adufour.filtering.Convolution1D)importClass(Packages.plugins.adufour.filtering.Kernels1D)importClass(Packages.icy.file.Saver)importClass(Packages.icy.file.Loader)importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog)importClass(Packages.plugins.adufour.thresholder.Thresholder)importClass(Packages.plugins.adufour.thresholder.KMeans)importClass(Packages.icy.sequence.SequenceUtil)f = FileDialog.open()seq = Loader.loadSequence(f, 0, true)sigma = 3kernelX = Kernels1D.CUSTOM_GAUSSIAN.createGaussianKernel1D(sigma).getData()kernelY = Kernels1D.CUSTOM_GAUSSIAN.createGaussianKernel1D(sigma).getData()seqf = seq.getCopy()Convolution1D.convolve(seqf, kernelX, kernelY, null)gui.addSequence(seqf)kmeans = KMeans.computeKMeansThresholds(seq, 2, 2, 255)result = Thresholder.threshold(seqf, 2, kmeans, false)result.setName(seq.getName() + " - thresholded")gui.addSequence(result)//f = FileDialog.save()//Saver.save(result, f, true, true)