Removing contour using Marvin Framework in Java
Asked Answered
P

1

19

I'm using Marvin Framework to get the veins pattern, but I don't know how to remove the leaf contour

I'm doing the following : (Each function calls its corresponding 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

Pinball answered 9/5, 2015 at 19:58 Comment(1)
I don't see how you could do this without identifying the background and preventing the background from being included when blurred.Visional
L
1

I've developed a simple approach that may help you. It just removes the leaf borders from left to right and from right to left.

The only implication is the leaf orientation. I've rotated your output image manually. However, I think you should consider leafs in that position for better analysis.

leaf_rotated.jpg:


(source: sourceforge.net)

leaf_rotated_out.jpg:


(source: sourceforge.net)

SOURCE CODE:

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;
                }
            }
        }
    }
}
Leannleanna answered 11/5, 2015 at 13:11 Comment(3)
Yeah, i already tried this, but the goal is to remove the contour using marvin plugins...Pinball
What do you mean with "goal"? Is it an exercise? What is the definition of the problem?Leannleanna
I think we should subtract its convex hull from the black-and-white image. But I don't know how to do it correctly in this framework.Nogas

© 2022 - 2024 — McMap. All rights reserved.