Thursday, March 12, 2009

High-boost filter

% High-boost filter
% Read a grayscale image and apply the average filter of size 3 x 3 for adding blur to the image.
% Applay the high-boost filter to enhance the image. Change the control
% parameter A value and check the enhanced resultant image.
clear all; close all; clc;
f=imread('moon.tif');
f=double(f);
f = filter2(fspecial('average',5),f);
subplot(1,3,1),imshow(uint8(f)),title('Original Image');
[m n]=size(f); A=1.1;
% w=[0 -1 0; -1 4+A -1;0 -1 0];
% b = imfilter(a,w);
for i=2:m-1
for j=2:n-1
b(i,j) = (A+4*f(i,j))+(-1*f(i-1,j))+(-1*f(i+1,j))+(-1*f(i,j-1))+(-1*f(i,j+1));
end
end
subplot(1,3,2),imshow(uint8(b)),title('High-Boost filtered Image');
for i=2:m-1
for j=2:n-1
if b(i,j)< 0
rimg(i,j)=A*(f(i,j)-b(i,j));
else
rimg(i,j)=A*(f(i,j)+b(i,j));
end
end
end
subplot(1,3,3),imshow(uint8(rimg)),title('High-Boost Enhanced Image');

No comments: