Thursday, March 29, 2012

Spatial Domain Filtering

Spatial Domain Filtering

Spatial Domain Filtering

This program demonstrate the image filtering in spatial domain using various types of box filters

Contents

Start

clear all;
close all;
clc;

Choose your mask

hLP = ones(3,3)/9;
hLap = [0 -1 0; -1 4 -1; 0 -1 0]; %Laplacian
hPreH = [-1 -1 -1; 0 0 0; 1 1 1]; %Prewitt
hPreV = [1 0 -1; 1 0 -1; 1 0 -1]; %Prewitt
hSobV = [1 0 -1; 2 0 -2; 1 0 -1]; %Sobel
hSobH = [-1 -2 -1; 0 0 0; 1 2 1]; %Sobel
hHP = [-1 -1 -1; -1 8 -1; 1 -1 -1]; %Sharpening
hHB = [-1 -1 -1; -1 8.2 -1; 1 -1 -1]; % High boost
hUnsharp = [-1 -1 -1; -1 1 -1; -1 -1 -1]/9; %Unsharp Masking

Read your image

x = imread('coins.png');
x = double(x)/255;

Filter the image

imLP = conv2(x,hLP,'same');
imLap = conv2(x,hLap,'same');
imPreH = conv2(x,hPreH,'same');
imPreV = conv2(x,hPreV,'same');
imPre = sqrt(imPreH.^2+imPreV.^2);
imSobH = conv2(x,hSobH,'same');
imSobV = conv2(x,hSobV,'same');
imSob = sqrt(imSobH.^2+imSobV.^2);
imHP = conv2(x,hHP,'same');
imHB = conv2(x,hHB,'same');
imUnsharp = conv2(x,hUnsharp,'same');

Display the result

Original Image
imshow(x);


Low Pass Image
figure; imshow(abs(imLP));


Laplacian Image
figure; imshow(abs(imLap));


Prewitt Operated Image
figure; imshow(abs(imPre));


Sobel Operated Image
figure; imshow(abs(imSob));


High Pass Image
figure; imshow(abs(imHP));
High Boost Filtering
figure; imshow(abs(imHB));


Unsharp Masking
figure; imshow(abs(imUnsharp));




No comments:

Post a Comment