Tuesday, September 27, 2011

Spatial Filtering etc


Assistance for Chapter 3 initial parts from Gonzalez and Woods,


Usage Help: Un-comment(Ctrl+T in Matlab) the required part of filtering and Run(F5) to understand the fun.
<Please keep a copy of a picture named as (1).jpg in the Matlab folder.

clc;

%% Read Image

X = imread('(1).jpg');
X = rgb2gray(X);

%% Histogram Equalisation of Image
% figure;
% imhist(X);
% figure;
% histeq(X);
% figure;
% imhist(histeq(X));

%% Gaussian Filtering of image
% fgauss = fspecial('gaussian',[3,3],1.0)
% filtim = imfilter(X,fgauss,'symmetric', 'conv');
% subplot(1,2,1)
% imshow(X);
% subplot(1,2,2)
% imshow(filtim);
% figure
% imshow(X-filtim);

%% Spatial Filtering Smoothing <Weighted> &High Boost Filtering
% favg = [1/16 2/16 1/16; 2/16 4/16 2/16; 1/16 2/16 1/16]
% filtim = imfilter(X,favg,'symmetric', 'conv');
% subplot(2,2,1)
% imshow(X);
% title('Original');
% subplot(2,2,2)
% imshow(filtim);
% title('Weighted Filtering');
% subplot(2,2,3)
% imshow(X-filtim);
% title('Difference Image');
% subplot(2,2,4)
% imshow(X+0.2.*(X-filtim));
% title('High Boost Sharpened');
%% Median Filtering <Doubt, Anybody who knows please assist in this, right now the code is substituting %Median of first block for all the blocks>
% filtim = imfilter(X,(double(median(median(X)))),'symmetric', 'conv');   %takes a single value for all the %matrices, how to make it floating
% subplot(2,2,1)
% imshow(X);
% title('Original');
% subplot(2,2,2)
% imshow(filtim);
% title('Median Filtering');
% subplot(2,2,3)
% imshow(X-filtim);
% title('Difference Image');

%% Laplacian

% flap1 = fspecial('laplacian', .2);
% filtim1 = imfilter(X,flap1,'symmetric', 'conv');
% flap2 = -flap1;
% subplot(2,2,1)
% imshow(X);
% title('Original');
% subplot(2,2,2)
% imshow(filtim1);
% title('Laplacian Filtering - 1');
% filtim2 = imfilter(X,flap2,'symmetric', 'conv');
% subplot(2,2,3)
% imshow(filtim2);
% title('Laplacian Filtering - 2');
% subplot(2,2,4)
% imshow(X+(filtim1));
% title('Reconstructed after Laplacian');
%%