Digital Image Processing
Impathon
RA2311026011123
Vikash Kumar
Add noise to portion of lake water apply
suitable filter where noise only the factors.
Subset the image with the dimension of
(15x15). Print the DN values from the subset
image for all channels.
Problem –
Simulate and then remove noise confined to the water region of a color
image.
Steps –
1. Load and normalize the image to [0,1].
2. Segment the lake by thresholding its blue channel to create a binary
mask.
3. Add zero-mean Gaussian noise only to pixels within that mask.
4. Denoise the noisy image using either a 5×5 Wiener filter or a 3×3
median filter (no Image Processing Toolbox required).
5. Extract a 15×15-pixel patch from the denoised image (starting at
the first lake pixel) and print its DN values for the red, green, and
blue channels.
Procedure
Load & normalize
I = im2double(imread('/mnt/data/[Link]'));
Mask lake
lakeMask = I(:,:,3) > 0.45;
Add noise only in mask
noisyI = I;
noiseStd = 0.05;
for c=1:3
ch = noisyI(:,:,c);
rnd = noiseStd*randn(size(ch));
ch(lakeMask) = ch(lakeMask)+rnd(lakeMask);
noisyI(:,:,c)=ch;
end
noisyI = min(max(noisyI,0),1);
Denoise w/o IPT
for c=1:3
denoisedI(:,:,c) = wiener2(noisyI(:,:,c),[5 5]);
% or medfilt2(noisyI(:,:,c),[3 3])
end
Extract & print 15×15
[r,c] = find(lakeMask,1);
r0=min(r,size(I,1)-14); c0=min(c,size(I,2)-14);
patch = denoisedI(r0:r0+14,c0:c0+14,:);
disp(patch(:,:,1)); disp(patch(:,:,2)); disp(patch(:,:,3));
Code –
I = imread('[Link]');
I = im2double(I);
blueChan = I(:,:,3);
lakeMask = blueChan > 0.45;
figure;
subplot(1,2,1), imshow(I), title('Original Image');
subplot(1,2,2), imshow(lakeMask), title('Lake Mask');
noisyI = I;
noiseStd = 0.05;
for c = 1:3
ch = noisyI(:,:,c);
rnd = noiseStd * randn(size(ch));
ch(lakeMask) = ch(lakeMask) + rnd(lakeMask);
noisyI(:,:,c) = ch;
end
noisyI = min(max(noisyI,0),1);
figure; imshow(noisyI), title('Noisy in Lake Region');
denoisedI = zeros(size(noisyI));
for c = 1:3
denoisedI(:,:,c) = imbilatfilt(noisyI(:,:,c));
end
figure; imshow(denoisedI), title('After Bilateral Filtering');
[idxR, idxC] = find(lakeMask);
r0 = min(idxR);
c0 = min(idxC);
r0 = min(r0, size(I,1)-14);
c0 = min(c0, size(I,2)-14);
subset = denoisedI(r0:r0+14, c0:c0+14, :);
figure; imshow(subset), title(sprintf('15×15 Patch @(%d,%d)',r0,c0));
fprintf('15×15 subset DN values (rows %d–%d, cols %d–%d):\n', ...
r0, r0+14, c0, c0+14);
for c = 1:3
fprintf('\n— Channel %d —\n', c);
disp(subset(:,:,c));
end
15×15 subset DN values (rows 1–15, cols 1–15):
Screenshots (Output) :-