removal of shadow area

11 views (last 30 days)
SHOBA MOHAN
SHOBA MOHAN on 7 Jan 2018
Commented: Monisha Gowda on 12 Apr 2020
I have used adaptive thresholding technique to distinguish foreground and background pixel as per the attachment in the link. https://www.mathworks.com/matlabcentral/fileexchange/8647-local-adaptive-thresholding?focused=6119920&tab=function
I have incorporated connected component analysis to the threshold coding.
I am attaching input and thresholded image here. Can anyone suggest me how to remove the shadow part alone.
function bw=adaptivethreshold(IM,ws,C,tm)
if (nargin<3)
error('You must provide the image IM, the window size ws, and C.');
elseif (nargin==3)
tm=0;
elseif (tm~=0 && tm~=1)
error('tm must be 0 or 1.');
end
IM=mat2gray(IM);
if tm==0
mIM=imfilter(IM,fspecial('average',ws),'replicate');
else
mIM=medfilt2(IM,[ws ws]);
end
sIM=mIM-IM-C;
bw=im2bw(sIM,0);
bw=imcomplement(bw);
Test Code:
clear;
close all;
% im1=imread('inputimage.jpg');
im2=imread('foregroundimage.jpg');
% bwim1=adaptivethreshold(im1,11,0.03,0);
bwim2=adaptivethreshold(im2,15,0.02,0);
% ModeFilterFunction = @(x) mode(x(:));
% modeImage = nlfilter(bwim2, [3 3], ModeFilterFunction);
CC = bwconncomp(bwim2,8);
S = regionprops(CC, 'Area');
L = labelmatrix(CC);
BW2 = ismember(L, find([S.Area] >= 100));
subplot(2, 2, 3);
imshow(BW2, []);
subplot(2,2,1);
imshow(im2);
subplot(2,2,2);
imshow(bwim2);
  3 Comments
SHOBA MOHAN
SHOBA MOHAN on 8 Jan 2018
Sorry for inconvenience now I am attaching foreground image. Thanks for the response.
Monisha Gowda
Monisha Gowda on 12 Apr 2020
Hi, Have you done it. I am also looking for the same. Can you help me on this?

Sign in to comment.

Answers (1)

Malhar Ashtaputre
Malhar Ashtaputre on 8 Jan 2018
Kindly go through following link for help in shadow removing:
  1 Comment
Maisha Maimuna
Maisha Maimuna on 8 Sep 2019
Hello Malhar Ashtaputre,
have you got the solution? I am stuck with the same problem.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!