Anda di halaman 1dari 11

Project Title: Spatial Domain Image Processing

Abstract Principle objective of Spatial Domain Image Processing is to process an image so that result is sharper than original image for specific application. Spatial Domain Image Processing techniques provide a multitude of choices for improving the visual quality of images. This project will provide an overview of underlying concepts, along with algorithms and programs commonly used for spatial filtering. The project focuses on techniques for image enhancement using various filters such as image enhancement using the laplacian filter and high-boost filtering.

Technical description Special Filtering: Spatial filtering is one of the principal tools used in this filter for a broad filtering is one of the principal tools for broad spectrum of applications. Filtering creates a new pixel with coordinates equal to the coordinates of the center of the neighborhood, and whose value is the result of the filtering operation. Filtering creates a new pixel with coordinates

equal to the coordinates equal to the coordinates of the neighborhood, and whose value is the result of the filtering option. If the operation performed on the image pixels is linear, then the filter is called linear spatial filter otherwise it is called non-linear spatial filter. Assuming w is a filter of matrix with 3x3 neighborhoods. At any point (x,y) in the image, the response g(x,y), of the filter is the sum of products of the filter coefficients and the image pixels encompassed by g(x,y)= w(-1,-1)f(x-1,y-1)+w(-1,0)f(x-1,y)+..+w(0,0)f(x,y)+.+w(1,1)f(x+1,y+1) In general

Algorithm spatial filter step 1: read the input image. step 2: convert the input image to double data type. step 3: enter the details of the filter step 4: create the padded matrix filled with zeros and with extra two rows and columns step 5: store the values of the input image in the padded matrix, by taking starting pixel of the image coordinates as (2,2) step 6: traverse the array and apply the filter (using the equation discussed above)in order to get the sum of all pixels step 7: the above output is the filtered image Enhancement Using the Laplacian The approach basically consists of defining a discrete formulation of the secondorder derivative and then constructing a filter mask based on that formulation. The

simplest isotropic derivative operator is the laplacian, in which, for a function (image) f(x,y) of two variables, is defined as

In discrete form

As laplacian is a derivative operator, its use highlights intensity discontinuities in an image and deemphasizes regions with slowly varying intensity levels. This will tend to produce images that have grayish edges lines and other discontinuities, all superimposed on a dark, featureless background. Background features can be recovered while still preserving the sharpening effect of laplacian simply by adding or subtracting (depends on the filter value) the laplacian image to the original.

Where f(x,y), g(x,y) are the input and sharpened images respectively. The constant c=-1 if the central coefficient is negative and c=1 if the central coefficient is positive. Algorithm step 1: use the spatial filter algorithm which gives the laplacian image step 2: calculate g(x,y) using the equation discussed above with the input as original image and laplacian image in step1 Unsharp Masking and High boosting filter A process commonly used by printing and publishing industry called unsharp masking, consists of the following steps 1. Blur the original image 2. Subtract the blurred image from the original image (the result is called the mask)

3. Add the mask to the original

here k is a weight. When k=1 - unsharp masking K>1 - high boost filtering

K<1 - de emphasize the contribution of the mask. The 1-D illustration is shown below, explains how unsharp masking works. The original image can be interpreted as a horizontal scan line through a vertical edge that transitions from a dark to a light region in an image. The blurred image is the result of smoothing, superimposed on the original signal. The unsharp mask in the below figure is obtained by subtracting the blurred signal from the original. The final sharpened image is obtained by adding the mask to the original signal.

Algorithm step1: read the input image step 2: create the blurred image using spatial filtering process algorithm step 3: obtain the unsharp image i.e. gmask using the equation provided in step 2. It subtracts blurred image from original image. step 3: calculate the mask image g(x,y) using the equation provided above which gives high boost image.

Discussion of results: Enhancement using laplacian The image in Figure-1(a) is before enhancement and Figure-1(b) through (c) are obtained after spatial filtering with the given filter [-1,-1,-1;-1, 8,-1;-1,-1,-1]. Figure-1(b) is obtained after doing spatial correlation of the laplacian filter with the input image which does double differentiation on input image, results in highlighting the boundaries of objects in the input image. The Figure-1(c) is obtained after adding Figure-1(b) to the original image

at k=-1, so that the boundaries of objects are added to the original image where the objects in the image can be observed clearly. Unsharp Masking The image in Figure-2(a) is before enhancement before high-boosting. By using the figure2(a) , a blurred image can be obtained using a filter 1/9[1,1,1;1,1,1;1,1,1] or Gaussian smoothing filter of 5x5 with sigma=3. The figure-2(b) is the blurred image which is slightly white text on a gray background. Figure-3(c) is the unsharp mask, obtained by equations discussed in theory above i.e. the mask is the difference between blurred image and original image hence the mask image is dark. Figure-2(d) was obtained using unsharp masking with k=1. The image is slightly better than original, the figure-2(e) shows the result using k=4.5 which is clearer then figure-2(d) as k>1 high-boosting in the image occurs. The change is due to addition of the mask to the original image. Results: Enhancement using laplacian

Figure-1(a)

figure-1(b)

Figure-1(c) Unsharp Masking

figure-2(a)

figure-2(b)

figure-2(c)

figure-2(d)

figure-2(e) 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

Conclusion: After completion of the project I came to know about the ways to enhance an image using various filters such as laplacian filter, high-boost filer etc. References 1. Gonzalez R.C, Woods R.E, Digital Image Processing, Pearson Education 2005. 2. www.wikipedia.com 3. www.mathworks.com

Anda mungkin juga menyukai