Remove shadow and unwanted background

조회 수: 9 (최근 30일)
TAN SAK JIE
TAN SAK JIE 2021년 6월 8일
답변: Joseph Cheng 2021년 6월 8일
How can I remove the shadow and extract only the object. I have try imadjust() . But the shadow is still there and during imbinarize(),it will include the shadow..so I cant minus it
Is it possible to make it into the desired picture ?
Before:
Desire

답변 (1개)

Joseph Cheng
Joseph Cheng 2021년 6월 8일
to get your started you can see that the tissue and the shadow area have similar values in all the color channels. you can do a bit of comparison of each of the color channels to generate a mask of those which are not gray and white:
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/645980/image.jpeg');
mtemp = double(img)./median(double(img),3);
subplot(311),imagesc(mtemp)
mtemp = mtemp-1;
subplot(312),imagesc(mtemp)
mtemp2 = abs(mtemp)<=.30;
mask = all(mtemp2,3);
subplot(313),imagesc(mask)
[row col N]=size(img);
for ind = 1:3
tempimg = img(:,:,ind);
tempimg(mask) = 255;
nimg(:,:,ind) = tempimg;
end
figure,imagesc(nimg)
axis equal
axis tight
which you can use a bit of imerode, bwfill, etc to edit the mask or generate something different.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by