100% found this document useful (4 votes)
9K views

Matlab Code For Gaussian Filter in Digital Image Processing

This MATLAB code performs Gaussian filtering on an image to reduce noise. It first reads in an image, pads it to the next power of 2, and takes the 2D FFT. It then generates a Gaussian filter kernel based on the image size and standard deviation. It applies the filter kernel to the image FFT by multiplying them element-wise, takes the inverse FFT, and displays the original and filtered images to compare the results.

Uploaded by

geonav_had
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
9K views

Matlab Code For Gaussian Filter in Digital Image Processing

This MATLAB code performs Gaussian filtering on an image to reduce noise. It first reads in an image, pads it to the next power of 2, and takes the 2D FFT. It then generates a Gaussian filter kernel based on the image size and standard deviation. It applies the filter kernel to the image FFT by multiplying them element-wise, takes the inverse FFT, and displays the original and filtered images to compare the results.

Uploaded by

geonav_had
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

matlab code for gaussian filter in digital image processing

[size=6][code]
f=imread('C:\Users\images\Image0671.jpg');
PQ=paddedsize(size(f));
F=fft2(f,PQ(1),PQ(2));
for i= 1:PQ(1)
for j=i:PQ(2)
H(i,j)=exp(-(i^2+j^2)); sigma=1; % should always be 1 for a gaussian noise
distribution as stated in the Matlab RANDN function
end
end
H=fftshift(H);
G=H.*F;
g=real(ifft2(g));
g=g(1:size(f,1),1:size(f,2));
figure,imshow(f)
figure,imshow(H)

I = imread('peppers.png');
H = fspecial('gaussian',2, 5);
I = imfilter(I, H);
imshow(I)
******************************************************************************

You might also like