Use the Plugin "Fill Holes" in my Plugin


I have the following problem:
I want to use the “Fill Holes” Pligin (Process-Binary-Fill Holes). I tried:

pic = (ImagePlus)IJ.runPlugIn(“ij.plugin.filter.Binary(“fill”)”, null);

But i get the following Error in Eclipse:

The left-hand side of an assignment must be a variable

But in the CommandFinder of ImageJ I found exactly this classname.

Can anybody help me please? …and yeah I started codeing with java and imagej a few days ago :wink:

Welcome to the forum @stefan_erben,

IJ.runPlugIn() does not return an instance of ImagePlus but rather an instance of the plugin that you are running (that’s why you try cast to ImagePlus I guess). That said, you will have to define a type for pic in Java like that:

ImagePlus pic = (ImagePlus) IJ.runPlugIn("ij.plugin.filter.Binary("fill")", null);

This, however, will still not work. You should instead use the method which takes a menu entry and executes the respective command. An alternative approach is, to directly use the Binary.fill(ImageProcessor ip, int foreground, int background) method. You can get the ImageProcessor from an ImagePlus using imp.getProcessor().

You can take a look at the Writing an ImageJ plugin documention for more information on such topics. If you have further questions, don’t hesitate to ask! :slight_smile:


1 Like

Thank you for your reply stelfrisch :slight_smile: ,

I desided to use the Binary.fill method, but I get the following error message in eclipse

The method fill(ImageProcessor, int, int) from the type Binary is not visible

I coded:

int foreground = 0;
int background = 255;
Binary.fill(binaer, foreground, background);

binaer is my ImageProcessor

Do you know why I have this problem? :confused:

I solved the problem, the picture was locked. Know I can use other plugins in my plugin:

ImagePlus binaerpic = IJ.getImage();
>> binaerpic.unlock(); <<
Prefs.blackBackground = false;, "Fill Holes", "");

For completeness sake, @stefan_erben, the fill() method is indeed not meant to be called from classes outside of the ij.plugin.filter package since it does not have an explicit access modifier set (also see the documentation on access control).