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

Gabriel Archanjo
  • 4,547
  • 2
  • 34
  • 41
The Eighth Ero
  • 417
  • 4
  • 13

1 Answers1

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;
                }
            }
        }
    }
}
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Gabriel Archanjo
  • 4,547
  • 2
  • 34
  • 41