/*
import the different Classes needed
- Icy is needed to use getSequence() and Icy.addSequence()
- Package thresholder is needed to do the threshold with
Thresholder and KMeans classes.
*/
importClass(Packages.icy.image.IcyBufferedImage)
importClass(Packages.plugins.tprovoost.bestthreshold.BestThreshold)
importPackage(Packages.plugins.adufour.thresholder)
/*
Get the focused Sequence. This is a shortcut for:
Icy.getMainInterface().getFocusedSequence()
*/
seq = getSequence()
img = getImage()
// working on first channel
channel = 0
// Check if sequence is null, as we cannot perform a threshold on
// something that does not exist.
if (img != null) {
data2 = BestThreshold.getHistogramBins(img, channel)
threshold = BestThreshold.Otsu(data2)
// performs the threshold and put the result (a sequence) inside a variable
result = Thresholder["threshold(icy.sequence.Sequence,int,double[],boolean)"](seq, 1, [threshold], false)
// display the result of the threshold
result.setName(seq.getName() + "thresholded")
gui.addSequence(result)
}