How to Non-uniform shadows removal in image ?

9 views (last 30 days)
I've tried to do by follow the method in this article, for remove the shadow. But now I can do only figure 3 and I can't continue doing because I don't understand in next step.
Please advise me or show me some code about next step to guide me. Sincerely Thanks.

Answers (5)

SHOBA MOHAN
SHOBA MOHAN on 29 Nov 2017
Hi Have you found the solution

M.Mahmud Hasan
M.Mahmud Hasan on 8 Aug 2018
I have the sameproblem.Have u got the solution??
  1 Comment
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.


Image Analyst
Image Analyst on 11 Aug 2018
This is as far as I got. It's up to a point where they fail to explain certain parameters in the image, like the angle of the sun, theta. A lot of other sentences in the paper are also incomprehensible, like has anyone ever heard of "histogram dissention"? I thought not.
% https://www.mathworks.com/matlabcentral/answers/334631-how-to-non-uniform-shadows-removal-in-image
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'Shadow Image.png';
folder = pwd;
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display image.
subplot(2, 2, 1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original Color Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Do color space conversion:
ycbcrImage = rgb2ycbcr(rgbImage);
yImage = ycbcrImage(:, :, 1);
cbImage = ycbcrImage(:, :, 2);
crImage = ycbcrImage(:, :, 3);
% Paper says "Next, focusing on the Y channel, its histogram is computed."
% NOTE: I have no idea why the histogram is needed, but here it is:
[counts, grayLevels] = imhist(yImage);
% Paper says "Histogram dissension gives us a higher contrast image in the Y channel."
% I, Google, and the Internet have no idea what "histogram dissension" is.
% Anyway, they don't say to compute a higher contrast image,
% nor do they later say to use such an image, they only use the original Y image.
% Get the average of the Y channel of the whole image.
yMean = mean2(yImage)
% Get the standard deviation of the whole image.
sdY = std2(yImage)
% Display the Y image.
subplot(2, 2, 2);
imshow(yImage);
impixelinfo;
title('Y Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
% Compute the standard deviation in a 3x3 window.
sdImage = stdfilt(yImage, true(3));
% Now sdImage is the std dev within a 3-by-3 window around each pixel.
% Display the image.
subplot(2, 2, 3);
imshow(sdImage, []);
impixelinfo;
title('Standard Deviation Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
% Shadow Pixels are defined as having a local standard deviation less than the standard deviation of the whole image.
shadowMask1 = sdImage < sdY; % Or do they really mean yMean - sdY??
% Display the image.
subplot(2, 2, 4);
imshow(shadowMask1, []);
impixelinfo;
title('Initial Shadow Mask', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
% Paper says "next, the non-shadow point’s mean and standard deviations
% for the sliding window are computed. Now, the pixels that have intensity
% less than the one standard deviation of the windows are considered shadow pixels."
shadowMask2 = yImage < sdImage; % True if Y (intensity) is less than the sd of the image in a 3x3 window cenetered around each pixel.
% Display the image.
figure;
subplot(2, 2, 1);
imshow(shadowMask2, []);
impixelinfo;
title('Second Shadow Mask', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
drawnow;
% Get rid of white small noise blobs in the second mask by using bwareaopen
smallestAllowableArea = 80;
shadowMask2 = bwareaopen(shadowMask2, smallestAllowableArea);
% Get rid of black small noise blobs in the second mask by using bwareaopen
% First find out what the areas are to begin with.
props = regionprops(shadowMask2, 'Area');
allAreas = sort([props.Area], 'descend')
shadowMask3 = ~bwareaopen(~shadowMask2, smallestAllowableArea);
% Display the image.
subplot(2, 2, 2);
imshow(shadowMask3, []);
impixelinfo;
title('Second Shadow Mask', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
% Paper says "The shadow model can be represented by the following formula:
% Il = (ti * cos theta Ld + Le) *Ri
% NOTE: It's not clear if only theta is inside the cos() or if theta*Ld is inside the cos().
  4 Comments
M.Mahmud Hasan
M.Mahmud Hasan on 13 Aug 2018
If you have any solution about shadow removal not like given solution please forward me .I am working with shadow removal.If you have any kind of solution that remove the shadow like the image i have given,please help me.I am stucking here for some days.I cant find any solution.
Image Analyst
Image Analyst on 13 Aug 2018
Sorry, I don't work with shadow removal. I suggest you contact people who do, like the authors of that paper.

Sign in to comment.


izza aditya
izza aditya on 1 Sep 2019
have you found the solution ?
  1 Comment
Image Analyst
Image Analyst on 8 Sep 2019
The authors in the paper did. I know it's not something that can be done (I really did try) because their paper leaves out necessary things, but if it's really needed by you then you will contact the authors.

Sign in to comment.


Maisha Maimuna
Maisha Maimuna on 8 Sep 2019
Have anyone found the solution? I am stuck with the shadow removal problem for some months

Community Treasure Hunt

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

Start Hunting!