Search code examples
javaimage-processingmarvin-framework

Marvin Image Processing Framework - Erosion plugin issue


I have a problem with Erosion plugin in Marvin Image Processing Framework. I want to do erosion, but unfortunately, after that I'm getting no image in output. This is my code:

tempPlugin  = new Erosion();
boolean[][] m = new boolean[][] {
{true,true,true},
{true,true,true},
{true,true,true}
};
tempPlugin.setAttributes("matrix", m);
resultImage = MarvinColorModelConverter.rgbToBinary(resultImage, 127);
tempPlugin.process(resultImage, resultImage);
resultImage = MarvinColorModelConverter.binaryToRgb(resultImage);
resultImage.update();
imagePanelNew.setImage(resultImage);

I'm using Java JDK 1.7 and Marvin Framework 1.5.0 Of course, I've tried do the same with .jar file, without changes.

Somebody could help me, please?


Solution

  • 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();
    }
    
    }