Thursday 17 March 2016

Image Processing With Matlab: One Dimensional Gausian Filter (Separable Filters)

Problem:

Implement the function SeparableGaussianBlurImage (image, sigma) to Gaussian blur an image using separable filters. ”sigma” is the standard deviation of the Gaussian. The separable filter should first Gaussian blur the image horizontally, followed by blurring the image vertically.






Main Function:

clear
close all
input = imread('Seattle.jpg');
%input=double(input);
input=rgb2gray(input);
im3=SeparableGaussianBlurImage(input,2);
figure(1)
imshow(uint8(input)), title('original');
figure(3)
imshow(uint8(im3)), title('Blurred');



Separable Filter:


function[out]=SeparableGaussianBlurImage(image,sigma)

A =image;
A=double(A);
sz1 = sigma+1;
sz=ceil(sz1/2);
[x]=meshgrid(-sz:sz);
[y]=transpose(x);
M = size(x,1)-1;
N = size(y,1)-1;
final_Output=A;
Exp_comp_x = -(x.^2)/(2*sigma*sigma);
Exp_comp_y = -(y.^2)/(2*sigma*sigma);
Kernel_x= exp(Exp_comp_x)/(2*pi*sigma*sigma);
Kernel_y= exp(Exp_comp_y)/(2*pi*sigma*sigma);
Output=A;

% Convolving in X direction

for i = 1:size(A,1)-M
    for j =1:size(A,2)-N
        Output(i,j)=sum(sum( A(i:i+M,j:j+M).*Kernel_x));
 
    end
end
Output = uint8(Output);
figure,imagesc(uint8(Output));

% Convolving in X direction

for i = 1:size(Output,1)-M
    for j =1:size(Output,2)-N
      final_Output(i,j) = sum(sum(A(i:i+M,j:j+M).*Kernel_y));
    end
end
out = final_Output;

Output:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home