Sei sulla pagina 1di 4

Appendix:

Matlab Codes:

File name: program1.m


%--------------------------------------------------------------------------
% The program enhances an image using laplatian filer by giving the input
% details of the filter
%--------------------------------------------------------------------------

% clearing previous results


clc;
clear all;

% importing an input image


InImg=imread('Fig0338(a)(blurry_moon).tif');

% displaying the output


figure(1);imshow(InImg);title('input image')
% calulating the laplatian tranform values for the input image by calling
% the spatial filter function
filtered_image=spatialfilter(InImg);

% displaying the filtered image


figure(2);imshow(filtered_image);title('filtered image')

% adding the filtered image to original image inorder to sharpen image


k=1;

% multiplying the filtered image with weight 3 and add the result to the
original image
value=mul(k,filtered_image);
OpImg=add(InImg,value);

% displaying the output image


figure(3);imshow(OpImg);title('Image after laplace transformation')

File name: program2.m


%--------------------------------------------------------------------------
% The program enhances an image using high-boosting filer by giving the input
% details of the filter
%--------------------------------------------------------------------------

% clearing previous results


clc;
clear all;

% importing an input image


InImg=imread('Fig0340(a)(dipxe_text).tif');

% displaying the output


figure(1);imshow(InImg);title('input image')
% calulating the blur image values for the input image by calling
% the spatial filter function
BlurImg=spatialfilter(InImg);

% displaying the blurred image output


figure(2);imshow(BlurImg);title('Blur image')

% obtaining unsharp mask


gmask=sub(InImg,BlurImg);

% displaying the unsharp mask image output


figure(3);imshow(gmask);title('unsharp mask image')

% defining the value of weight


k=1;
% multiplying the mask image with weight 3 and add the result to the
% original image
val=mul(k,gmask);
weighed_image=add(InImg,val);

% displaying the unsharp mask image output


figure(4);imshow(weighed_image);title('output image')

% defining the value of weight


k=4.5;
% multiplying the mask image with weight 3 and add the result to the
% original image
val=mul(k,gmask);
weighed_image=add(InImg,val);

% displaying the unsharp mask image output


figure(5);imshow(weighed_image);title('output image')

File name: spatialfilter.m


function [img]=spatialfilter(InImg)
% Usage: [OpImg]= spacialfilter (inImg);
%
% Inputs: InImg
%
% Output: OpImg = returns the output image after filtering of image
%
% Author: Naga Surya Sandeep Angara
% Date: 02/08/2014

% taking the values to filter


filter=input('Enter the filter values 3X3 matrix in the format
[n,n,n;n,n,n;n,n,n]: ')

% converting the input image to double class


TempImg=im2double(InImg);

% get size of the input image


[row col]=size(TempImg);
% create padded matrix filled with zeros
g = zeros (row+2, col+2);

% store input image in g


for i = 1:1:row
for j = 1:1:col
g(i+1, j+1) = TempImg(i,j);
end
end

% traverse the array and apply the filter inorder to get the sum of all
% pixels. This helps to get the bounderies of various objects in the image
for i = 1:1:row
for j = 1:1:col
img(i,j) = g(i,j)*filter(1,1) + g(i+1,j)*filter(2,1) +
g(i+2,j)*filter(3,1)+ g(i,j+1)*filter(1,2) + g(i+1,j+1)*filter(2,2) +
g(i+2,j+1)*filter(3,2)+ g(i,j+2)*filter(1,3) + g(i+1,j+2)*filter(2,3) +
g(i+2,j+2)*filter(3,3);
end
end

img=im2uint8(img);
end

File name: add.m


function [output]= add (input1,input2)
% Usage: [OpImg]= add (input1,input2);
%
% Inputs: image1 = input
% imgae2 = input
% Output: OpImg = returns the output image after addition of input1 and
% input2
%
% Author: Naga Surya Sandeep Angara
% Date: 02/08/2014

%--------------------------------------------------------------------------
% Check for right number of parameters
%--------------------------------------------------------------------------
if nargin ~= 2
error('Requires two input arguments addition(image1,image2)');
exit 1
end

output=input1 + input2;
end

File name: mul.m


function [output]= mul (input1,input2)
% Usage: [OpImg]= mul (input1,input2);
%
% Inputs: image1 = input
% imgae2 = input
% Output: OpImg = returns the output image after multiplying pixel to pixel
% of input1 and input2
%
% Author: Naga Surya Sandeep Angara
% Date: 02/08/2014

%--------------------------------------------------------------------------
% Check for right number of parameters
%--------------------------------------------------------------------------
if nargin ~= 2
error('Requires two input arguments addition(image1,image2)');
exit 1
end
input1=im2double(input1);
input2=im2double(input2);
output=input1 .* input2;
output=im2uint8(output);
end

Potrebbero piacerti anche