AutoThresholding - Huang: ArrayIndexOutOfBound



Just stumbled across this one:

Large images seem to overtax the Huang threshold computation.

working on the following image:, the macro bellow

import ij.IJ

opener = new Opener()
imp ='/path/to/downloaded/huang-test.tif'), "Auto Threshold", "method=Huang white");


java.lang.ArrayIndexOutOfBoundsException: 255
	at fiji.threshold.Auto_Threshold.Huang(
	at fiji.threshold.Auto_Threshold.exec(
	at ij.IJ.runUserPlugIn(
	at ij.IJ.runPlugIn(
	at ij.Executer.runCommand(

I also tested ops on the gray-scale image:

# @Img(label='img') img

#@OpService ops
#@UIService ui

bw = ops.threshold().huang(img)

this works like a charm.

I also had a quick look at and called it with run() and exec(), but that worked too.
So probably there is some other code running when calling it from the macro as indicated above?


The version in github is the latest one, but although the commit was pushed, it hasn’t been packed to be updated in Fiji yet. If you can compile it yourself, then note that in this latest version, the “Huang” method was reverted to the original code (which is slow with 16bit images). The version that gives you an error (yes I was able to reproduce it) has been renamed as Huang2 and left there for compatibility with old macros. It is very quick with 16 bit images, but uses a different formula (written by Johannes Schindelin) and sometimes triggers an error like this, which I have not been able to fully understand.


thanks for looking into this @gabriel


@FelixM can I upload your sample image to github in case somebody can investigate why the Huang2 method fails in certain circumstances? Please be aware that the image will be visible to the internet. Thank you.


Hi @gabriel. sure, feel free to use the image for testing.


@FelixM thank you very much,