Vous êtes sur la page 1sur 8

Histograms and Spatial Filtering Project 2 ECE 4783 Ronnie Moate 9 MAR 2012 9 MAR 2012

Abstract
In this project, there were two primary objectives. The first objective was to create a histogram of the original images intensity level values. Once the histogram was created, the image should then be altered by a process called histogram equalization. After the image has gone through this process, a new histogram should then be constructed from the images new intensity values. The second part of this project involves spatial filtering. The first task to be completed is taking an image, and then placing a Laplacian Filter across the intensity values. Once completed, an unsharp masking filter is created to place across the intensity values to create a clearer image. Upon completion of these sections of this project, it helps one to visualize the results of various aspects of image alteration through histograms and spatial filters. This includes bar graphs that give an operator visual information on intensity value distribution, image clarity through Laplacian Filters, and image sharpening through unsharp filters.

Technical Discussion
A histogram is a graphical representation of the intensity values of an image. This information is useful to understand the breakdown of the images intensity levels. A graphical representation of the intensity levels also helps the user to alter the image to maximize intensity equalization. Histogram manipulation can be used for image enhancement. The more an images intensity levels are equalized; the image will have a higher contrast. In creating a histogram, the x axis corresponds to the intensity values and the y axis ( ) corresponds to the values represented by the equation: Another equation can be used for the y axis which corresponds to the normalized values. This ( ) equation is: In both of these equations, refers to the intensity values and refers to the number of pixels with intensity values. M*N refers to the size of the actual image, i.e. the image has M by N pixels. When completing histogram equalization, the objective is to find a function such that the histogram of the resulting image is very close to being uniform. This function is defined as: ( ) ( ) ( )

The second part of the project has two parts. The first part is to create a Laplacian spatial filter and use that to enhance the image. Enhancing an image by a Laplacian spatial filter will sharpen the image which will allow more detail to be easily seen. This process calls for the use of two variables, one for the x direction and one for the y direction. The Laplacian is the simplest isotropic derivative operator which is defined as: When this equation is solved for the two variables, the discrete Laplacian equation becomes: ( ) ( ) ( ) ( ) ( ) ( )

This equation cannot be used alone. It has to be implemented using a filter mask which gives an isotropic result for rotations in increments of 90o. The filter mask is defined as a 3 by 3 matrix as follows: 0 1 0 1 -4 1 0 1 0 The Laplacian is a derivative operator which means that it uses highlight intensity discontinuities in an image and deemphasizes regions with slowly varying intensity levels. Background features are often recovered while the sharpening can be preserved by subtracting the laplacian image to the original. This is done because the filter has a negative center.

The second part of the special filtering objective is creating an unsharp masking filter and applying it to an image. This process is completed by blurring the original image then subtracting the blurred image from the original. This result is what is called the mask. Then the mask is added to the original image. This is accomplished by the use of some basic equations; ( ) ( ) ( ) these equations are: where ( is: ) is the blurred image. Then the equation for adding the mask to the original image ( ) ( ) ( )

In the above equation, an unsharp mask is defined when k=1.

Results
The results for the first objective of the lab was to create a histogram for an image, then use a function to equalize the histogram and show the resulting image and histogram. The function that was used is described in the technical discussions. The histogram that was created for the original images intensity values is shown in Figure 1. This histogram shows a range of values that are normalized using the equation ( ) . These normalized values range from 0 to 256. Then upon completion of the histogram, I created a series of loops and codes that made use of the transfer function to equalize the histogram. The resulting image can be found in Figure 3 and the histogram containing the equalized intensity values can be found in Figure 4. The resulting image seems to have been altered in a way that harms the images contrast. The original image is much clearer and has better color ranges which make the contrast and visibility better. Figure 1. Histogram of original Image Figure 2. Original Image

Figure 3. Histogram Equalized Image

Figure 4. Equalized Histogram

( ) The basic way to sharpen an image using the Laplacian is by: ( ) ( ) where f(x,y) is the input and g(x,y) is the sharpened image. This formula was ( ) is shown in the technical discussions. implemented into my code. The solved function In this solved function, there are portions that refer to negatve and positive integers added and subtracted to the range of M and N. Since the M and N values range the size of the image, a zero padding equation had to be implemented into the program to change the size of the image by adding two pixels to the height and width. The new image size ranged from 1 to M+2 and from 1 to N+2. After the padding was complete, the image center had to be shifted from image(x,y) to (x+1,y+1). This allowed the proper use of the filter and the equation had to be changed from: ( ) ( ) ( ) ( ) ( ) ( ) to: ( ) ( ) ( ) ( ) ( ) ( ) The original image is found in Figure 5 and the resulting image using Laplacian is found in Figure 6. The Laplacian image is much clearer and better.

Figure 5. Original Image

Figure 6. Laplacian Image

Then for the last part of the project, unsharp masking is implemented on an image. This consists of subtracting and unsharp version of an image from the images original version to sharpen it. The same process is used as the Laplacian to obtain the resulting image with the exception of subtracting the unsharp image. These details of how it works can be found in the technical discussion. I found that the resulting images were not that different. The original image can be found in Figure 7 and the unsharp masked image can be found in Figure 8. I found the the use of the Laplacian is much more effective than the use of unsharp masking. Figure 7. Original Image

Figure 8. Unsharp Masked Image

Appendix
Histogram Equalization
image=imread('Fig0308_a__fractured_spine_.tif'); pixels=size(image,1)*size(image,2); figure,imshow(image); hist=uint8(zeros(size(image,1),size(image,2))); f=zeros(1,256); pf=zeros(256,1); pc=zeros(1,256); eq=zeros(1,256); c=zeros(1,256); output=zeros(1,256); for i=1:size(image,1) for j=1:size(image,2) value=image(i,j); f(value+1)=f(value+1)+1; pf(value+1)=f(value+1)/pixels; end end figure,bar(pf); sum=0; b=255; for i=1:size(pf) sum=sum+f(i); c(i)=sum; pc(i)=c(i)/pixels; output(i)=round(pc(i)*b); end for i=1:size(image,1) for j=1:size(image,2) hist(i,j)=output(image(i,j)+1); end end for i=1:size(hist,1)

for j=1:size(hist,2) value=hist(i,j); f(value+1)=f(value+1)+1; eq(value+1)=f(value+1)/pixels; end end figure,bar(eq); figure,imshow(hist); imwrite(image,'hist_origianl.tif'); imwrite(hist,'hist_enhanced.tif');

Laplacian
clc; close all; clear all; image=imread('Fig0338_a__blurry_moon_.tif'); [m n]=size(image); lap=-1; a=1;b=1;c=1;d=1; e=-4; for x=1:m+2 for y=1:n+2 if x==1 || x==m+2; new(x,y)=0; else if y==1 || y==n+2; new(x,y)=0; end end end end for x=1:m for y=1:n new(x+1,y+1)=image(x,y); end end for x=1:m for y=1:n grad=a*new(x,y+1)+b*new(x+1,y)+c*new(x+1,y+2)+d*new(x+2,y+1)... +e*new(x+1,y+1); newer(x,y)=new(x+1,y+1)+lap*(grad); laplacian(x,y)=uint8(newer(x,y)); end end figure,imshow(image); figure,imshow(laplacian); imwrite(laplacian,'lap_moon.tif')

Unsharp Masked
clc; close all; clear all; image=imread('Fig0340_a__dipxe_text_.tif'); [m n]=size(image); a=1;b=1;c=1;d=1;e=1;f=1;g=1;h=1;i=1;k=1; for x=1:m+2 for y=1:n+2 if x==1 || x==m+2; new(x,y)=0; else if y==1 || y==n+2; new(x,y)=0; end end end end for x=1:m for y=1:n new(x+1,y+1)=image(x,y); end end for x=1:m for y=1:n sharp(x,y)=image(x,y)+k*(image(x,y)-(round((a*new(x,y)... +b*new(x+1,y)+c*new(x+2,y)+d*new(x,y+1)+e*new(x+1,y+1)... +f*new(x+2,y+1)+g*new(x,y+2)+h*new(x+1,y+2)+i*new(x+2,y+2))... /9))); mask(x,y)=uint8(sharp(x,y)); end end figure, imshow(image); figure, imshow(mask); imwrite(mask,'unsharp.tif')

Vous aimerez peut-être aussi