how to remove shadow from the rgb image
Mostrar comentarios más antiguos
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
my output image
.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);
Respuestas (2)
Image Analyst
el 29 de Dic. de 2018
1 voto
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.

5 comentarios
syed salma banu s
el 29 de Dic. de 2018
syed salma banu s
el 29 de Dic. de 2018
Image Analyst
el 29 de Dic. de 2018
Editada: Image Analyst
el 29 de Dic. de 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
el 14 de Jun. de 2019
Sir, how to get the backgroung part (apart from leaf) in white color.
Image Analyst
el 14 de Jun. de 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.
Keerthi D
el 29 de Jun. de 2020
0 votos
The complex leaf image background is first removed to get a clear leaf sample before further processing. So l using here background elimination mathod. Algorithm is, 1.Manually select ROI in I and store it in R. 2.generate binary mask. 3. set J to I. 4.for each pixel (m,n)in I 5. if pixel(m,n) is in R 6. set J(m,n) to 1. 7. else 8. Set J(m,n) to 0. 9.compute complement J'. 10.set I to I+J'. 11.Crop I to eliminate unwanted image parts. Please send me it's Matlab code. My email ID : keerthidev36@gmail.com </matlabcentral/answers/uploaded_files/323605/Screenshot_20200629_165725.jpg>
7 comentarios
Keerthi D
el 29 de Jun. de 2020
Image Analyst
el 29 de Jun. de 2020
You can see from my answer that the shadow was not included in the masked image.
Keerthi D
el 29 de Jun. de 2020
But if l changed the background from black to white , that time shadow will be there.
Keerthi D
el 29 de Jun. de 2020
Can you please solve the above algorithm.
Image Analyst
el 29 de Jun. de 2020
I believe I solved syed's question with my own algorithm.
I'm not sure your "Answer" and algorithm does.
Keerthi D
el 2 de Jul. de 2020
Okey. How to remove shadow on the leaf image
Keerthi D
el 2 de Jul. de 2020

Categorías
Más información sobre Agriculture en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!