c. add p=5+sin(x/0.8+y/0.6); periodic noise to your image. remove the added noise using a notch filter. clean the image. in matlab

To add periodic noise to an image, we can use the following code:

main.m
% Load image
img = imread('path/to/image');

% Add noise
[x, y] = size(img);
[xGrid, yGrid] = meshgrid(1:y, 1:x);
noise = 5 + sin(xGrid/0.8 + yGrid/0.6);
noisyImg = double(img) + noise;

% Display noisy image
imshow(uint8(noisyImg));
234 chars
12 lines

To remove the added noise using a notch filter, we can use the following code:

main.m
% Calculate DFT of image
F = fft2(noisyImg);

% Create notch filter to remove noise
notchFilter = ones(size(F));
notchY = round(y/2) + [-5:5];
notchX = round(x/2) + [-5:5];
notchFilter(notchX, notchY) = 0;
notchFilter(y-notchX+1, x-notchY+1) = 0;

% Apply notch filter
cleanF = F .* notchFilter;

% Inverse DFT to obtain cleaned image
cleanImg = real(ifft2(cleanF));

% Display cleaned image
imshow(uint8(cleanImg));
417 chars
19 lines

Note that we assumed a noise frequency of 1.25 cycles per pixel in the x direction and 1.67 cycles per pixel in the y direction.

Alternatively, we can use the bandstop2 function from the Image Processing Toolbox to create the notch filter:

main.m
% Calculate DFT of image
F = fft2(noisyImg);

% Create notch filter to remove noise
cx = round(y/2) + 0.25*y*cos(pi/4);
cy = round(x/2) - 0.25*x*sin(pi/4);
BW = 0.1;
notchFilter = 1 - bandstop2(size(F), BW, [cy cx]);

% Apply notch filter
cleanF = F .* notchFilter;

% Inverse DFT to obtain cleaned image
cleanImg = real(ifft2(cleanF));

% Display cleaned image
imshow(uint8(cleanImg));
387 chars
18 lines

This code uses a band-stop filter to remove the noise. The notch frequency and bandwidth can be adjusted as needed.

related categories

gistlibby LogSnag