NOTICE! This is a static HTML version of a legacy Fiji BugZilla bug.

The Fiji project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Bug 1183 - ij.process.AutoThresholder and fiji.threshold.Auto_Threshold return different values
ij.process.AutoThresholder and fiji.threshold.Auto_Threshold return different...
Status: RESOLVED WONTFIX
Product: Fiji
Classification: Unclassified
Component: Plugins
unspecified
Macintosh Mac OS
: P4 normal
Assigned To: ImageJ Bugs Mailing List
Depends on:
Blocks:
 
Reported: 2015-11-04 05:18 CST by Radoslaw Ejsmont
Modified: 2015-11-06 09:54 CST
2 users (show)

See Also:

Description Radoslaw Ejsmont 2015-11-04 05:18:18 CST
Hi,

I have been developing a jython script ij which I needed to autothreshold some stacks. I have first used the ij.process.AutoThresholder using histogram I got from the following snipplet:

```
for zsliceno in range(1, stack.getSize() + 1):
	zslice = stack.getProcessor(zsliceno)
	if zsno == 1:
		histogram = zslice.getHistogram()
	else:
		temp = zslice.getHistogram()
		for i in range(0, len(histogram)):
			histogram[i] += temp[i]
thresholder = AutoThresholder()
threshold = thresholder.getThreshold("Moments", histogram)
```

calling the plugin gives a different value:

```
thresholder = Auto_Threshold()
anarray = thresholder.exec(image, "Moments", False, False, True, True, False, True)
```

The image is 16-bit. These seems to be a bug in ij.process.AutoThresholder, or I am doing something terribly wrong :)

Information about your version of Java:

  os.arch => x86_64
  os.name => Mac OS X
  os.version => 10.11.1
  java.version => 1.8.0_51
  java.vendor => Oracle Corporation
  java.runtime.name => Java(TM) SE Runtime Environment
  java.runtime.version => 1.8.0_51-b16
  java.vm.name => Java HotSpot(TM) 64-Bit Server VM
  java.vm.version => 25.51-b03
  java.vm.vendor => Oracle Corporation
  java.vm.info => mixed mode
  java.awt.graphicsenv => sun.awt.CGraphicsEnvironment
  java.specification.name => Java Platform API Specification
  java.specification.version => 1.8
  sun.cpu.endian => little
  sun.desktop => null
  file.separator => /

The up-to-date check says: REMIND_LATER

Information relevant to JAVA_HOME related problems:

  JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home//jre
  imagej.dir => /Applications/Fiji.app

Information about the version of each plugin:

Activated update sites:
ImageJ: http://update.imagej.net/ (last check:20151026205651)
Fiji: http://update.fiji.sc/ (last check:20151028163859)
3D ImageJ Suite: http://sites.imagej.net/Tboudier/ (last check:20151103085731)

Files not up-to-date:
  968c6425 (MODIFIED) 20151103165434 Contents/Info.plist
  3af43208 (MODIFIED) 20150906115145 jars/jython-shaded-2.7.0.jar
  e85a2018 (LOCAL_ONLY) 20150121223046 plugins/DeconvolutionLab/DeconvolutionLab_.jar
  71331805 (LOCAL_ONLY) 20100820154940 plugins/jacop_.jar
Comment 1 Wayne Rasband 2015-11-05 22:26:16 CST
The ij.process.AutoThresholder class currently only works with 8-bit histograms. To threshold a 16-bit image, ImageJ converts the image to 8-bits, gets the threshold and then scales it to a 16-bit threshold. This JavaScript demonstrates how to get the thresholds of each image in a 16-bit stack.

  imp = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip");
  stack = imp.getStack();
  for (i=1; i<=stack.getSize(); i++) {
    ip = stack.getProcessor(i);
    ip.setAutoThreshold("Moments dark");
    print(i+" "+ip.getMinThreshold());
  }

I updated the AutoThresholder JavaDocs to make it clear that it only works with 8-bit images.
Comment 2 Radoslaw Ejsmont 2015-11-06 04:28:30 CST
And for the stack histogram threshold I would combine stack into a single ImageProcessor and use same functions?
Comment 3 Wayne Rasband 2015-11-06 09:54:22 CST
Here is an example that shows how to get the threshold of an entire stack:

  imp = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip");
  IJ.setAutoThreshold(imp, "Default dark stack");
  ip = imp.getProcessor();
  print("threshold: "+ip.getMinThreshold());

I used the command recorder (Plugins>Macros>Record) to generate the first two lines of code.