Skip to content

Segmenting non-3-channel image with SAM2 Large yields wrong and unfriendly error #9

@ctrueden

Description

@ctrueden

Error message in the console:

SAM2 Large experienced an error: Currently EfficientViTSAMJ only supports 1-channel (grayscale) or 3-channel (RGB, BGR, ...) 2D images.The image dimensions order should be 'xyc', first dimension width, second height and third channels.
java.lang.IllegalArgumentException: Currently EfficientViTSAMJ only supports 1-channel (grayscale) or 3-channel (RGB, BGR, ...) 2D images.The image dimensions order should be 'xyc', first dimension width, second height and third channels.
	at ai.nets.samj.models.Sam2.checkImageIsFine(Sam2.java:375)
	at ai.nets.samj.models.Sam2.setImageOfInterest(Sam2.java:278)
	at ai.nets.samj.models.AbstractSamJ.setImage(AbstractSamJ.java:297)
	at ai.nets.samj.communication.model.SAM2Large.setImage(SAM2Large.java:128)
	at ai.nets.samj.gui.ModelSelection.loadModel(ModelSelection.java:75)
	at ai.nets.samj.gui.MainGUI.lambda$loadModel$15(MainGUI.java:248)
	at java.base/java.lang.Thread.run(Unknown Source)

To reproduce:

  • File > Open Samples > Neuron (5 channels)
  • SAMJ Annotator > SAM2 Large model > Go!

Suggested fix is two-fold:

  1. Change the language not to hardcode the name EfficientViTSAMJ which is confusing when the model is not EfficientViTSAM.
  2. Rather than dumping the stack trace to the console, display an error dialog box using IJ.error("SAMJ Annotator", errorMessage);. Dump the stack trace using the SciJava LogService's debug method, so that it only pops up the console while running in debug mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions