简体   繁体   English

Marvin图像处理框架 - 侵蚀插件问题

[英]Marvin Image Processing Framework - Erosion plugin issue

I have a problem with Erosion plugin in Marvin Image Processing Framework. 我在Marvin Image Processing Framework中遇到了Erosion插件的问题。 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. 我正在使用Java JDK 1.7和Marvin Framework 1.5.0当然,我已尝试对.jar文件执行相同操作,无需更改。

Somebody could help me, please? 有人可以帮帮我吗?

There are some issues in your code. 您的代码中存在一些问题。 You are not using Marvin properly. 你没有正确使用马文。

1. Loading plug-in 1.加载插件

You must create an Erosion plug-in using MarvinPluginLoader : 您必须使用MarvinPluginLoader创建一个Erosion插件:

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. 因此,Erosion插件和依赖项(因为插件可能使用其他插件)被正确加载。

2. In the case of Erosion, you cannot use the same image object as input and output image 2.在侵蚀的情况下,您不能使用相同的图像对象作为输入和输出图像

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 : 下面是一个源代码,它实现了Erosion Plug-in页面中显示的相同结果:

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM