Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB - How to eliminate shadowed background on an image

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);
like image 823
zkanoca Avatar asked Nov 09 '22 11:11

zkanoca


1 Answers

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

like image 177
zkanoca Avatar answered Nov 15 '22 07:11

zkanoca