MATLAB Answers

how to remove shadow from the rgb image

57 views (last 30 days)
syed salma banu s
syed salma banu s on 29 Dec 2018
Commented: Image Analyst on 14 Jun 2019
Hi,
I am doing my project in leaf disease detection and classification. i have to do background removal for image preprocessing .but still i got the shadow of leaf in the image. i am struggling to remove the shadow .please can anyone suggest me the appropriate solution .
This is my initial iimage
sample1.JPG
my output image
Screenshot (59).png
and my code to remove the background
I=imread('sample1.jpg');
imshow(I);
I=im2double(I);
img=rgb2gray(I);
imshow(img);
size(img);
mask = zeros(size(img));
mask(25:end-25,25:end-25) = 1;
maskimg=activecontour(img,mask,300);
imshow(maskimg);
maskimg=im2uint8(maskimg);
maskimg=imcomplement(maskimg);
imshow(maskimg);
maskimg=im2double(maskimg);
channel1 = maskimg(:,:,1);
channel2 = maskimg(:,:,1);
channel3 = maskimg(:,:,1);
actualImg = cat(3,channel1,channel2,channel3);
imshow(actualImg);
res=imadd(I,actualImg);
imshow(res);
res1=rgb2lab(res);
imshow(res1);
res1=imadd(I,res);
imshow(res1);

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 29 Dec 2018
Use the Color Thresholder on the Apps tab of the tool ribbon. Then fill holes and take the largest blob. Erase the background, if you want to. See attached m-file.
0000 Screenshot.png

  5 Comments

Show 2 older comments
Image Analyst
Image Analyst on 29 Dec 2018
To get the background, you simply invert the mask, like this:
maskedRgbImage = bsxfun(@times, rgbImage, cast(~mask, 'like', rgbImage));
Is this solved enough for you now to "Accept this answer"? If not, what else to we need to do to solve your original question about removing shadow?
Damodar Reddy Ch
Damodar Reddy Ch on 14 Jun 2019
Sir, how to get the backgroung part (apart from leaf) in white color.
Image Analyst
Image Analyst on 14 Jun 2019
You can say
out = rgbImage % Initialize output image.
mask3d = cat(3, mask, mask, mask); % Create mask
out(~mask3d) = 255; % Apply the mask.
Now out should have white everywhere outside the leaf.

Sign in to comment.

Sign in to answer this question.