Bug: Menu Image | Type => ClassCastException: DirectColorModel cannot be cast to IndexColorModel

imagej
bug

#1

In recent versions of ImageJ (e.g. the latest 1.52c) I get

java.lang.ClassCastException: java.awt.image.DirectColorModel cannot be cast to java.awt.image.IndexColorModel

when converting an RGB color image to for instance HSB stack via the menu, Image | Type.

This problem did not exist with for instance ImageJ 1.51k which I now use as a temporary replacement.

Thanks,

Peter Meijer


#2

@petex, I am unable to reproduce this problem using the 4200x4200 Nile Bend sample image on a Mac running macOS 10.12.6 and Java 1.8.0_172. What are you using?


#3

Also unable to reproduce this on Windows 10 Enterprise 64 bit, ImageJ 1.52c: Java 1.8.0_172. For the record.


#4

Hi Wayne,

When I download and open the image from https://imagej.nih.gov/ij/images/NileBend.jpg and apply
Image | Type | HSB stack, I get as first lines in the ImageJ exception window the system info
(I’m using Windows 10 Pro 64-bit)

ImageJ 1.52c; Java 1.8.0_101 [32-bit]; Windows 10 10.0; 359MB of 640MB (56%)

java.lang.ClassCastException: java.awt.image.DirectColorModel cannot be cast to java.awt.image.IndexColorModel

Maybe it is a Java version issue? The older version of ImageJ 1.51k that I tried and that gives
no problems also has an older Java version (under Window | Show info, because I get no exception):

ImageJ 1.51k; Java 1.6.0_24 [64-bit]; Windows NT (unknown) 6.2; 55MB of 12212MB (<1%)

However, you are also using almost the same recent version of Java, though on a Mac.

Thanks,

Peter


#5

I updated Java references now but still get

ImageJ 1.52c; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 360MB of 640MB (56%)

java.lang.ClassCastException: java.awt.image.DirectColorModel cannot be cast to java.awt.image.IndexColorModel


#6

I made the ImageJ.cfg content identical for ImageJ 1.51k and for ImageJ 1.52c (on the same machine of course), and yet 1.51k works fine but 1.52c gives me the exception on the NileBend.jpg image.

ImageJ.cfg content:

.
C:\Program Files\Java\jdk1.8.0_172\bin\javaw.exe
-Xmx2000m -cp ij.jar ij.ImageJ

Not sure what else needs straightening up. I remember that I also worked without problems with the HSB stack feature on my home PC yesterday (another Windows 10 Pro 64-bit system) until I updated ImageJ to the latest version 1.52c. I do not know what the version was before I updated. No problem with Lab Stack, but RGB Stack and HSB Stack both give the reported exception.

Thanks,

Peter


#7

Yet another test: via Help | Update ImageJ I updated my existing ImageJ 1.51k installation, which worked fine in doing the HSB Stack operation on the NileBend.jpg image, thus arriving at ImageJ 1.52c, but now that gives the aforementioned exception upon doing HSB Stack. I’ll now be restoring my ImageJ 1.51k installation…

Peter


#8

@petex, I am unable to reproduce this problem using Windows 10 and Java 1.8.0_172. Please post the full exception stack trace.


#9
ImageJ 1.52c; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 275MB of 2000MB (13%)
 
java.lang.ClassCastException: java.awt.image.DirectColorModel cannot be cast to java.awt.image.IndexColorModel
	at ij.process.ByteProcessor.<init>(ByteProcessor.java:40)
	at ij.ImagePlus.setupProcessor(ImagePlus.java:791)
	at ij.ImagePlus.getProcessor(ImagePlus.java:810)
	at ij.plugin.ImageInfo.getImageInfo(ImageInfo.java:51)
	at ij.macro.Functions.getImageInfo(Functions.java:1678)
	at ij.macro.Functions.getStringFunction(Functions.java:258)
	at ij.macro.Interpreter.getStringTerm(Interpreter.java:1360)
	at ij.macro.Interpreter.getString(Interpreter.java:1338)
	at ij.macro.Interpreter.doStringAssignment(Interpreter.java:970)
	at ij.macro.Interpreter.doAssignment(Interpreter.java:752)
	at ij.macro.Interpreter.doStatement(Interpreter.java:267)
	at ij.macro.Interpreter.doBlock(Interpreter.java:635)
	at ij.macro.Interpreter.runUserFunction(Interpreter.java:333)
	at ij.macro.Interpreter.doUserFunctionAssignment(Interpreter.java:926)
	at ij.macro.Interpreter.doAssignment(Interpreter.java:754)
	at ij.macro.Interpreter.doStatement(Interpreter.java:267)
	at ij.macro.Interpreter.doBlock(Interpreter.java:635)
	at ij.macro.Interpreter.runFirstMacro(Interpreter.java:734)
	at ij.macro.Interpreter.doStatement(Interpreter.java:285)
	at ij.macro.Interpreter.doStatements(Interpreter.java:235)
	at ij.macro.Interpreter.run(Interpreter.java:118)
	at ij.macro.Interpreter.run(Interpreter.java:89)
	at ij.macro.Interpreter.run(Interpreter.java:100)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:145)
	at ij.IJ.runMacroFile(IJ.java:153)
	at ij.macro.Functions.runMacro(Functions.java:3534)
	at ij.macro.Functions.getStringFunction(Functions.java:263)
	at ij.macro.Interpreter.getStringTerm(Interpreter.java:1360)
	at ij.macro.Interpreter.getString(Interpreter.java:1338)
	at ij.macro.Interpreter.doStatement(Interpreter.java:303)
	at ij.macro.Interpreter.doBlock(Interpreter.java:635)
	at ij.macro.Interpreter.runMacro(Interpreter.java:158)
	at ij.macro.MacroRunner.run(MacroRunner.java:152)
	at ij.macro.MacroRunner.run(MacroRunner.java:125)
	at ij.plugin.MacroInstaller.runMacroCommand(MacroInstaller.java:441)
	at ij.Executer.runCommand(Executer.java:140)
	at ij.Executer.run(Executer.java:66)
	at ij.IJ.run(IJ.java:302)
	at ij.IJ.run(IJ.java:277)
	at Show_ScanID_Always.imageUpdated(Show_ScanID_Always.java:24)
	at ij.ImagePlus.notifyListeners(ImagePlus.java:2432)
	at ij.ImagePlus.updateAndDraw(ImagePlus.java:270)
	at ij.ImagePlus.updateAndRepaintWindow(ImagePlus.java:360)
	at ij.ImagePlus.setSlice(ImagePlus.java:1576)
	at ij.ImagePlus.setPosition(ImagePlus.java:1480)
	at ij.ImagePlus.setStack(ImagePlus.java:699)
	at ij.process.ImageConverter.convertToHSB(ImageConverter.java:139)
	at ij.plugin.Converter.convert(Converter.java:100)
	at ij.plugin.Converter.run(Converter.java:25)
	at ij.IJ.runPlugIn(IJ.java:192)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:66)
	at java.lang.Thread.run(Thread.java:748)

#10

@petex, it looks like you are running a macro when the exception is thrown. Do you get an exception when you manually open the Nile Bend sample image and use the Image>Type>HSB Stack command? If you do, please post the full stack trace. If you don’t, please post a small macro that reproduces the problem.


#11

Opening the image via File | Open made no difference for the exceptions, but that was probably because the Show_ScanID_Always() is called from AutoRun in StartupMacros.ijm. However, simply recompiling the macro, hence regenerating the .class file, fixed the exceptions! Apparently something changed between ImageJ 1.51k and ImageJ 1.52c that broke compatibility. The content of Show_ScanID_Always.java is of the simple form

import ij.*;import ij.plugin.*;

public class Show_ScanID_Always implements PlugIn, ImageListener {
  
   public void run(String arg) {
      ImagePlus.addImageListener(this);
   }
   
   public void imageOpened(ImagePlus imp) {
   // Do something
   }
   public void imageClosed(ImagePlus imp) {}
   public void imageUpdated(ImagePlus imp) {
   // Do something
   }
}

When I restore the older Show_ScanID_Always.class I get my exceptions back, and when I put the newly compiled one back in place the exceptions are gone. I do not know what has changed between ImageJ 1.51k and ImageJ 1.52c that could have caused this. I did not have to change one letter of the source code, only regenerate the .class file.

Thanks!

Peter


#12

Could it be that imageUpdated() is now called for every stack frame and in earlier ImageJ versions perhaps not?


#13

@petex, please test the latest daily build (1.52d23) with the original Show_ScanID_Always.class. The daily build has bug fixes that should prevent the ClassCastExceptions you were getting with ImageJ 1.52c.


#14

Great! Replacing the ij.jar of ImageJ 1.52c by today’s wsr.imagej.net/download/daily-build/ij.jar (1.52d24 according to ImageJ) indeed prevents the exceptions with creating HSB Stack for NileBend.jpg. Putting the previous ij.jar back in place brings back the exceptions. So it appears you have cracked it! In the mean-time I got the impression that with 1.52c the generation of the 3 frames of HSB Stack caused 3 imageUpdated() events which would then call my macro in rapid-fire succession - something that this macro was never designed for but also something that had previously not caused problems. It could explain why I got 2 exception windows for 3 generated frames.

Thanks a lot!

Peter