Image Processing Using Matlab: Gaussian Filter Without using Matlab Inbuilt Function
Problem:
Implement the function GaussianBlurImage(image, sigma) to Gaussian blur an image. ”sigma” is the standard deviation of the Gaussian. Implement the Gaussian blur using a 2D filter without using inbuilt Matlab Functions.
Sol:
Original Image:
main Script:
clear
close all
input = imread('Seattle.jpg');
input=rgb2gray(input);
im3=GaussianBlurImage(input,4);
figure(1)
imshow(uint8(input)), title('original');
figure(3)
imshow(im3), title('Blurred');
Gaussian BlurImage function definition :
function[Out]=GaussianBlurImage(image, sigma)
tic %To calculate the time taken by the function
A=image;
I=double(A);
Output=image;
sz1 = sigma+1;
window_size=ceil(sz1/2);
[x,y]=meshgrid(-window_size:window_size,-window_size:window_size);
M = size(x,1)-1;
N = size(y,1)-1;
Exp_comp = -(x.^2+y.^2)/(2*sigma*sigma);
Kernel= exp(Exp_comp)/(2*pi*sigma*sigma);
I = padarray(I,[window_size,window_size]);
%Convolution
for i = 1:size(I,1)-M
for j =1:size(I,2)-N
Output(i,j) =sum(sum( I(i:i+M,j:j+M).*Kernel));
end
end
Out= Output;
toc
Modified Image:
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home