MorpholIbJ labelToRGB gives java.lang.ArrayIndexOutOfBoundsException: 255

imagej
morpholibj

#1

Hi guys,

I get an error inside the following code:

# colorize the labels
if LABEL_COLORIZE:
    log.info('Colorize Lables ...')
    maxLabel = 255
    bgColor = Color.BLACK
    shuffleLut = True
    lutName = CommonLabelMaps.GOLDEN_ANGLE.getLabel()

    # Create a new LUT from info in dialog
    lut = CommonLabelMaps.fromLabel(lutName).computeLut(maxLabel, shuffleLut)

    #  Create a new RGB image from index image and LUT options
    pastack_rgb = LabelImages.labelToRgb(pastack, lut, bgColor)

		# convert to rgb color
    IJ.run(pastack_rgb, "RGB Color", "slices")

which I do not really understand, since the maxLabel is set to 255. The output from my script until here was:

[INFO] Starting ...
[INFO] Filename                      : C:\Output\Atomic_3D_Object_Detection\Raw-HR-NLM_segmented_B.czi
[INFO] Label Connectivity            : 6
[INFO] Label Output BitDepth         : 16
[INFO] Colorize Labels               : True
[INFO] Minimun Voxel Size            : 200
[INFO] Headless Mode                 : False
[INFO] ------------  START IMAGE ANALYSIS ------------
[INFO] Opening Image: C:\Output\Atomic_3D_Object_Detection\Raw-HR-NLM_segmented_B.czi
[INFO] File Extension   : .czi
[INFO] Start Processing ...
[INFO] Border Extension ...
[INFO] Filtering VoxelSize - Minimum : 200
[INFO] Labels Filtered : 1062
[INFO] 3D Particle Analysis ...
[INFO] Colorize Lables ...

and this is the error message:

Started 3d_analytics.py at Tue Mar 13 15:36:09 CET 2018
Traceback (most recent call last):
  File "C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py", line 169, in <module>
    objstack, results, labels = run(imagefile)
  File "C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py", line 85, in run
    imp = ImageTools.getseries(imps, series=IMAGESERIES)
AttributeError: class ImageTools has no attribute 'getseries'

	at org.python.core.Py.AttributeError(Py.java:205)
	at org.python.core.PyClass.noAttributeError(PyClass.java:182)
	at org.python.core.PyObject.__getattr__(PyObject.java:1008)
	at org.python.pycode._pyx0.run$1(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py:137)
	at org.python.pycode._pyx0.call_function(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:138)
	at org.python.core.PyFunction.__call__(PyFunction.java:413)
	at org.python.pycode._pyx0.f$0(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py:195)
	at org.python.pycode._pyx0.call_function(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1386)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:40)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Started 3d_analytics.py at Tue Mar 13 15:37:35 CET 2018
Traceback (most recent call last):
  File "C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py", line 171, in <module>
    objstack, results, labels = run(imagefile)
  File "C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py", line 130, in run
    pastack_rgb = LabelImages.labelToRgb(pastack, lut, bgColor)
	at inra.ijpb.label.LabelImages.labelToRgb(LabelImages.java:681)

	at inra.ijpb.label.LabelImages.labelToRgb(LabelImages.java:602)

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

	at java.lang.reflect.Method.invoke(Method.java:497)


java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 255

	at org.python.core.Py.JavaError(Py.java:546)
	at org.python.core.Py.JavaError(Py.java:537)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
	at org.python.core.PyObject.__call__(PyObject.java:496)
	at org.python.core.PyObject.__call__(PyObject.java:500)
	at org.python.pycode._pyx4.run$1(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py:139)
	at org.python.pycode._pyx4.call_function(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:138)
	at org.python.core.PyFunction.__call__(PyFunction.java:413)
	at org.python.pycode._pyx4.f$0(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py:197)
	at org.python.pycode._pyx4.call_function(C:\Users\Public\Documents\Fiji\scripts\3d_analytics.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1386)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:40)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 255
	at inra.ijpb.label.LabelImages.labelToRgb(LabelImages.java:681)
	at inra.ijpb.label.LabelImages.labelToRgb(LabelImages.java:602)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
	... 28 more

Any ideas, why this happens?


#2

Hi,

the LabelToRgb function in MorphoLibJ converts a label image (containing integer values between 0 and a given number N) to a color image. It assumes the second argument is a int[][] array with at least N elements. I suspect the LUT that is used has only 255 elements, while the label values are larger. In fact, it seems the number of labels is around 1060.

When creating the LUT (I suppose in your 3d_analytics.py script, before line 130), you can use the following:
byte[][] lut = CommonLabelMaps.GLASBEY.computeLut(maxLabel, shuffleLut);

Hope this helps,
David


#3

Thx. I overlooked that one. Now it works.