InteractiveMarkerControlledWatershed plugin from MorpholibJ used in Maven Project from IntelliJ

I try to use Interactive Marker Controlled Watershed plugin from my maven project like this:

ImagePlus labeledImage = BinaryImages.componentsLabeling( imgpls, 4, 8 );;
inra.ijpb.plugins.InteractiveMarkerControlledWatershed IW = new inra.ijpb.plugins.InteractiveMarkerControlledWatershed();"");

And I get this error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at inra.ijpb.plugins.InteractiveMarkerControlledWatershed$CustomWindow.<init>(
	at inra.ijpb.plugins.InteractiveMarkerControlledWatershed$
	at java.awt.event.InvocationEvent.dispatch(
	at java.awt.EventQueue.dispatchEventImpl(
	at java.awt.EventQueue.access$500(
	at java.awt.EventQueue$
	at java.awt.EventQueue$
	at Method)
	at java.awt.EventQueue.dispatchEvent(
	at java.awt.EventDispatchThread.pumpOneEventForFilters(
	at java.awt.EventDispatchThread.pumpEventsForFilter(
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(
	at java.awt.EventDispatchThread.pumpEvents(
	at java.awt.EventDispatchThread.pumpEvents(

Furthermore, I’ve tried opening the image without having any opened window (removing the and even though and Open Dialog pops up and I indicate the image I want to work on, the code stops running and I get a null as a return. Thanks for the help!

Hello @CamilaDuitama,

Sorry for the late answer. From the error message, it seems the problem is on this line on the plugin code:

Toolbar.getInstance().setTool( Toolbar.POINT );

For this line to work, you need to have ImageJ already open. Maybe that’s missing?

Hi @iarganda ,

I was planning to use this as an API inside Java without having ImageJ opened. Maybe this is not possible?



In that case you shouldn’t use the interactive version of the plugin but either the API methods of the inra.ijpb.watershed.MarkerControlledWatershed3D (or 2D) class, or the static methods of the inra.ijpb.watershed.Watershed class. You have an example of the latest in this script.