5

I am trying to process a picture. There is an RGB leaf photograph and I want to exract the leaf's itself only.

The procedure I follow is

  1. I read image from file
  2. Convert to grayscale
  3. Apply 5x5 median filter
  4. Convert to BW

enter image description here

enter image description here

As you see the shadow on the bottom right corner sticks to the BW image. Is there a method to select the leaf only.

I = imread(files{404});

hcsc = vision.ColorSpaceConverter;        
hcsc.Conversion = 'RGB to intensity';       
Ig = step(hcsc, I);

medFilt= vision.MedianFilter([f f]);
Ig = step(medFilt, Ig);

at = vision.Autothresholder;        
Ibw = step(at, Ig);
Dima
  • 37,098
  • 13
  • 69
  • 112
zkanoca
  • 8,468
  • 8
  • 42
  • 87
  • 3
    Why do you convert to grayscale? You could perhaps convert to HSV and select the leaf based on a hue range. See [this anwer](http://stackoverflow.com/a/4064205/2586922) – Luis Mendo Jun 15 '15 at 11:05
  • @LuisMendo I have never thought that. I will try. – zkanoca Jun 15 '15 at 11:07

1 Answers1

1

Instead of converting to grayscale image, I convert it to HSV and take its V part. It results better now.

I = imread(files{404});

I = rgb2hsv(I);

Ig = I(:,:,3);

medFilt= vision.MedianFilter([f f]);
Ig = step(medFilt, Ig);

at = vision.Autothresholder;        
Ibw = step(at, Ig);

enter image description here

zkanoca
  • 8,468
  • 8
  • 42
  • 87