This document provides MATLAB code for shadow detection and removal from an image. It includes steps for loading an image, applying a median filter for noise removal, estimating shadow regions, detecting shadow pixels, and removing shadows using an energy function. Finally, the processed image is saved as 'shadow_removed_output.jpg'.
This document provides MATLAB code for shadow detection and removal from an image. It includes steps for loading an image, applying a median filter for noise removal, estimating shadow regions, detecting shadow pixels, and removing shadows using an energy function. Finally, the processed image is saved as 'shadow_removed_output.jpg'.
img = imread('your_image.jpg'); % Replace with your filename img = im2double(img); % Convert to double precision for processing figure, imshow(img), title('Original Image');
% Step 2: Apply Contra-Harmonic Mean Filter for Noise Removal
Q = 1.5; % Order of Contra-Harmonic filter filtered_img = img; for i = 1:3 % Apply filter to each RGB channel filtered_img(:,:,i) = medfilt2(img(:,:,i), [3 3]); % Using median filtering end figure, imshow(filtered_img), title('Filtered Image (Noise Removed)');
% Step 3: Compute the Mean RGB Values (Shadow Region Estimation)