There are some issues in your code. You are not using Marvin properly.
1. Loading plug-in
You must create an Erosion plug-in using MarvinPluginLoader:
tempPlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.morphological.erosion");
Thus, the Erosion plug-in and dependencies (since a plug-in might use other plug-ins) are properly loaded.
2. In the case of Erosion, you cannot use the same image object as input and output image
You must use two references, for instance cloning:
tempPlugin.process(resultImage.clone(), resultImage);
Example:
Below is presented a source code that achieves the same result presented in the Erosion Plug-in Page:
public class SimpleExample {
private MarvinImagePlugin tempPlugin;
public SimpleExample(){
// 1. Load and set up plug-in.
tempPlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.morphological.erosion");
boolean[][] m = new boolean[][] {
{true,true,true},
{true,true,true},
{true,true,true}
};
tempPlugin.setAttributes("matrix", m);
// 2. Load image
MarvinImage image = MarvinImageIO.loadImage("./res/erosion_in.png");
MarvinImage resultImage = MarvinColorModelConverter.rgbToBinary(image, 127);
// 3. Process and save image
tempPlugin.process(resultImage.clone(), resultImage);
resultImage = MarvinColorModelConverter.binaryToRgb(resultImage);
resultImage.update();
MarvinImageIO.saveImage(resultImage, "./res/erosion_out.png");
}
public static void main(String[] args) {
new SimpleExample();
}
}