Jython script for thresholding images

Hi everyone,

I would like to threshold some 3 channel images with a jython script.
First I want to threshold all 3 channels, then I want to dilate the binary mask of the 2nd channel:
I found this to start with:

Here is my code:

#@ String(label="Threshold Method", required=true, choices={'otsu', 'huang'}) method_threshold
#@ OpService ops
from ij import IJ
image = IJ.openImage()
image.show()

thresholded = ops.run("threshold.%s" % method_threshold, image)

Now i would like to display thresholded. But it is no Image object but a Default Datatype.
Thus thresolded.show() does not work. How can I convert it back to an Image like image is?
After that I want to run IJ.run(thresholded, “Dilate”, “”). This gives me the error that thresholded is no ij.ImagePlus object.

Thanks for your help!

Good day,

did you try the recorder with Java or Javascript option?

However, if you struggle with a scripting language, why not use the ImageJ macro language that is really easy to use and to record by using the macro recorder. In your case I see no advantage of a scripting language compared to the macro language.

Regards

Herbie

Yes I now tried it with the recorder and got a command to do the threshold.
I use the scripting language because I run more analysis tasks than I mentioned above.
Thank you!