java - 在 Java 中使用 Marvin 框架去除轮廓

标签 java image-processing pattern-recognition marvin-framework

我正在使用 Marvin Framework得到叶脉图案,但我不知道如何去除叶子轮廓

我正在做以下事情: (每个函数调用其对应的 Marvin Plugin。):

    MarvinImage source = MarvinImageIO.loadImage("source.jpg");

    MarvinImage gsImage = grayscaleImage(source);

    MarvinImage blImage1 = blurEffect(gsImage.clone(),1);

    MarvinImage blImage2 = blurEffect(blImage1.clone(), 13);

    MarvinImage difi = subtract(blImage2.clone(), blImage1.clone());

    difi = invertC(difi.clone());

    difi = closingEffect(difi.clone());

    difi = MarvinColorModelConverter.binaryToRgb(difi.clone());

    difi = reduceNoise(difi.clone());

    difi = invertC(difi.clone());

    MarvinImageIO.saveImage(difi, "result.jpg");

enter image description here

enter image description here

最佳答案

我开发了一种可能对您有所帮助的简单方法。它只是从左到右和从右到左删除叶边界。

唯一的含义是叶方向。我已经手动旋转了您的输出图像。但是,我认为您应该考虑将叶子置于该位置以便更好地进行分析。

leaf_rotated.jpg:


(来源:sourceforge.net)

leaf_rotated_out.jpg:


(来源:sourceforge.net)

源代码:

public class LeafTest {

    public static void main(String[] args) {

        MarvinImage image = MarvinImageIO.loadImage("./res/leaf_rotated.jpg");
        removeBorder(image);
        MarvinImageIO.saveImage(image, "./res/leaf_rotated_out.jpg");
    }

    private static void removeBorder(MarvinImage image){

        // left to right
        for(int y=0; y<image.getHeight(); y++){
            for(int x=0; x<image.getWidth(); x++){

                if(image.getIntComponent0(x, y) > 10){

                    for(int x2=x; x2<image.getWidth() && x2 < x+40; x2++){
                        image.setIntColor(x2, y, 0,0,0);
                    }

                    x=0;
                    break;
                }
            }
        }

        // right to left
        for(int y=0; y<image.getHeight(); y++){
            for(int x=image.getWidth()-1; x>=0; x--){

                if(image.getIntComponent0(x, y) > 10){

                    for(int x2=x; x2>=0 && x2 > x-40; x2--){
                        image.setIntColor(x2, y, 0,0,0);
                    }

                    x=image.getWidth()-1;
                    break;
                }
            }
        }
    }
}

关于java - 在 Java 中使用 Marvin 框架去除轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30144412/

相关文章:

java - Spring Kafka- 试图了解事物在幕后是如何工作的

matlab - 高斯高通滤波器的公式

python - Python 中字符串的模式检测

java - 如何设置 Spring Cloud Zuul 服务器作为代理服务器

java - 什么时候保存函数的结果比再次调用它更好?

java - Spring 启动: header value encoding

python - Python/OpenCV 中的对比度拉伸(stretch)

python - 比较两个图像与 python 排除阴影

python - 寻找重复出现的模式

Python 字符串模式识别/压缩