MATLAB - How to eliminate shadowed background on an image

343 views Asked by At

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);
1

There are 1 answers

0
zkanoca On BEST ANSWER

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