Auto threshold not working in image


#1

I want to threshold an image but it doesn’t seem to work in Java Eclipse. Here’s a snippet of the code:

ImagePlus[] channelsRGB = ChannelSplitter.split(duplicate);
ImagePlus Gchannel = channelsRGB[1];
IJ.setAutoThreshold(Gchannel, "Triangle dark");

The error displayed is as follows:

A thresholded image or 8-bit binary image is required. Threshold levels can be set using the Image->Adjust->Threshold tool.

How do I fix this?


#2

@kbimagej

What is your input image? Is it an RGB? Because I believe only 8- and 16-bit images are supported for this function. So you can convert it first to a RGB Stack or split channels first… anyone else on this one?

Just double-check its properties… you can attach it here too for us to test out.

eta


#3

Hi etarena,

The image ‘duplicate’ is an RGB image. ‘ChannelSplitter.split’ does split the image into different channels i.e. R, G, and B plane. You could take any color image but the error persists.

Thanks and Regards,
kb@imagej


#4

@kbimagej -

This is the code that I ran and it’s working for me…

import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.plugin.ChannelSplitter;

public class Main {

public static void main(String[] args) {
		// start ImageJ
		new ImageJ();

		// open the FluorescentCells sample (to test single slice images)
		ImagePlus image = IJ.openImage("http://imagej.net/images/lena-std.tif");
		ImagePlus[] imageChannels = ChannelSplitter.split(image);
		imageChannels[1].show();
		ImagePlus Gchannel = imageChannels[1];
		IJ.setAutoThreshold(Gchannel, "Triangle dark");
     }
}

Again - I wasn’t able to test your image with this… I did the “Lena” sample image that comes with Fiji - and it worked just fine. Would you be able to share your image file?

eta