Showing posts with label Matlab Filter. Show all posts
Showing posts with label Matlab Filter. Show all posts

Tuesday, October 18, 2011

Point detection, Laplacian of Gaussian and High Boost Filtering


As with other posts, remove the commenting part in the below code to see the code working.
Pre-requisite You know imread, imshow and other functions in MATLAB.

clc;

%% Read Image
    %Reads the Image into an array for further processing
X = imread('build.tif');
    %X = rgb2gray(X);
   
%% Point detection
Y = imread('turbine.tif');
%Y1= bwareaopen(Y, 20);
% fplap = [1 1 1; 1 -8 1; 1 1 1]      %Laplacian at a point
fplap = [0 1 0; 1 -4 1; 0 1 0]      %Laplacian at a point
filtim = imfilter(Y,fplap,'symmetric', 'conv');

subplot(2,2,1)
imshow(Y);
title('Original');

subplot(2,2,2)
imshow(filtim);
title('Laplacian Point Filtered');

subplot(2,2,3)
imshow(Y-filtim);
title('Difference Image');

%% Gaussian Filtering of image
% fgauss = fspecial('gaussian',[25,25],4.0)
%         % 25X25 Gaussian filter with SD =25 is created.
% filtim = imfilter(X,fgauss,'symmetric', 'conv');
%         % Filter the image by convolution with the above designed filter.
%         % filtim now contains the gaussian filtered image.
%        
% subplot(2,2,1)
% imshow(X);
% title('Original');
%
% subplot(2,2,2)
% imshow(filtim);
% title('Gaussian Filtered');
%
% subplot(2,2,3)
% imshow(X-filtim);
% title('Difference Image');
%
% % flap1 = fspecial('laplacian', .2);
% % filtim1 = imfilter(filtim,flap1,'symmetric', 'conv');
%
% % fsobel = [-1 0 1; -2 0 2; -1 0 1]      %Grad in y
% fsobel = [-1 -2 -1; 0 0 0; 1 2 1]      %Grad in x
% % fsobel = [0 -1 -2; 1 0 -1; 2 1 0]        %45 degree
% filtim1 = imfilter(filtim,fsobel,'symmetric', 'conv');
%
% subplot(2,2,4)
% imshow(filtim1);
% title('LoG Image');

%% 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');

%%

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');
%%