add gaussian noise with parameters m=0, v=0.04 to your image. filter the noise you add in the frequency domain with a low-pass filter. in matlab

Here's how you can add Gaussian noise with mean m=0 and variance v=0.04 to an image using imnoise function in MATLAB:

main.m
original_image = imread('image.jpg'); % replace with your image file name
noisy_image = imnoise(original_image, 'gaussian', m, v);
131 chars
3 lines

To filter the added noise in the frequency domain using a low-pass filter, you can follow these steps:

  1. Compute 2D FFT of the noisy image using fft2:
main.m
F = fft2(noisy_image); % compute 2D FFT
40 chars
2 lines
  1. ShiftFFT to center frequency using fftshift:
main.m
Fs = fftshift(F); % shift FFT to center frequency
50 chars
2 lines
  1. Create a low-pass filter using fspecial:
main.m
filter_size = 15; % set filter size
filter_sigma = 5; % set filter standard deviation
lpf = fspecial('gaussian', [filter_size, filter_size], filter_sigma); % create low-pass filter
181 chars
4 lines
  1. Filter the FFT using element-wise multiplication:
main.m
filtered_Fs = Fs .* lpf; % filter FFT
38 chars
2 lines
  1. Shift the filtered FFT back to the original position using ifftshift:
main.m
filtered_F = ifftshift(filtered_Fs); % shift filtered FFT back
63 chars
2 lines
  1. Compute the inverse 2D FFT using ifft2:
main.m
filtered_image = ifft2(filtered_F); % compute inverse FFT
58 chars
2 lines
  1. Remove the imaginary part of the image using real:
main.m
filtered_image = real(filtered_image); % remove imaginary part
63 chars
2 lines

Here's the complete code:

main.m
original_image = imread('image.jpg'); % replace with your image file name
noisy_image = imnoise(original_image, 'gaussian', m, v);

F = fft2(noisy_image); % compute 2D FFT
Fs = fftshift(F); % shift FFT to center frequency

filter_size = 15; % set filter size
filter_sigma = 5; % set filter standard deviation
lpf = fspecial('gaussian', [filter_size, filter_size], filter_sigma); % create low-pass filter

filtered_Fs = Fs .* lpf; % filter FFT
filtered_F = ifftshift(filtered_Fs); % shift filtered FFT back
filtered_image = ifft2(filtered_F); % compute inverse FFT
filtered_image = real(filtered_image); % remove imaginary part
627 chars
15 lines

related categories

gistlibby LogSnag