Monday, June 29, 2009

Activity 4 Enhancement by Histogram Manipulation

The histogram of a grayscale image is equal to the graylevel probability
distribution function (PDF) if normalized by the total number of pixels. As such,
the grayscale PDF of an image can be modified in the same way one can modify
the PDF of random numbers.
Histogram manipulation is one way of improving the quality of an image,
enhancing certain image features, or mimicking the response of different imaging
systems, such as the human eye.
Given the cumulative distribution function (CDF) of a desired PDF, the grayscale
PDF of an image can be modified by backprojecting the grayscale values using
the CDF. Then
newly encountered functions in scilab:
tabul - frequency of values of a matrix or vector
tabul allows
you to compute the frequency of of occurence of a vector or matrix
[m]=tabul(X [,order])
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Activity 4:
Two categories of image enhancement techniques include spatial and frequency domain techniques. Spatial techniques involve direct manipulation of image pixels while frequency domain techniques works by manipulation of fourier of the and wavelet transform of a signal.
Here, the spatial technique will used by way of histogram enhancement. The histogram of an image illustrate the distribution of gray levels in the image in the range 0 to 255 where 0 is black and 255 is white and normalized when in the range [0.0, 1.0].
The method of histogram enhancement works by equalization.This is one of the ways in which it can be done in Scilab:
You get the histogram of the image by using the tabul(filename, ‘i’) command that gives the frequency of occurrence of the matrix or vectors, or in this case the no. of pixels having that graylevel and then plot it.
The histogram:
x axis for the graylevel
y axis for the frequency value

Next, normalize the greylevel and you distribute the frequency over the total no. of pixels and thus spread out the most frequent intensity values.


Results and discussions:



Using linear method of histrogram equalization, we see in Fig.1 that the resulting new image has a well distributed histogram as compared to the original image which has uneven probability distribution. The new image has a higher contrast than the original.


In Figure 2, using nonlinear histogram equalization using interp1(,,'linear') was used. However the resulting image has lower contrast than the original.

For this image the linear method was able to enhance the contrast in the image while the non linear method was not and only resulted to reduction in grayvalue of each graylevel.


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Code:
linear

im=imread('C:\Users\USA\Desktop\scilab and 186\grayscale parrot.png');

m=tabul(im,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(321);

imshow(im,[]);

subplot(322);

plot(nx,ny);

title('PDF1- Histogram 1');xlabel('grayscale level');ylabel('frequency');

subplot(323);

plot(nx,ccy);

title('CDF1');

//2. backprojection of the image through the CDF original

newim= [];

for i = 1:px

for j = 1:py

newim(i,j) = ccy(im(i,j));

end

end

subplot(324);

imshow(newim,[]);

//scf(1);

//imshow(newim,[]);

//imwrite(good1, 'newim.jpg');

/////for this newimage get the PDF and CDF again

im=imread('C:\Users\USA\Desktop\scilab and 186\newim.jpg');

im=tabul(newim,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(325);

plot(nx,ny);

title('PDF2- Histogram of Image 2');xlabel('grayscale level');ylabel('frequency');

subplot(326);

plot(nx,ccy)

title('CDF of Image 2');

xs2sgif(0,’figure1.gif’);


code: non linear:


im=imread('C:\Users\USA\Desktop\scilab and 186\grayscale parrot.png');

m=tabul(im,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(321);

imshow(im,[]);

subplot(322);

plot(nx,ny);

title('PDF1- Histogram 1');xlabel('grayscale level');ylabel('frequency');

subplot(323);

plot(nx,ccy);

title('CDF1');

// for the equalization by backprojection of the image through a desired cdf

xx=[0:1:255];

yy=xx^2;

yy=yy/max(yy);

xxp=[];

yyp=[]

for i=1:px;

for j=1:py;

xxp(i, j)=ccy(im(i,j));

end

end

yyp=interp1(yy,xx, xxp,'linear');

//yyp=interp1(yy,xx, xxp,' spline');

//yyp=interp1(yy,xx, xxp,'nearest);

newim=yyp;

subplot(324);

imshow(newim, []);

newim=round(newim);

subplot(324);

imshow(newim,[]);


im=imread('C:\Users\USA\Desktop\scilab and 186\newim.jpg');

im=tabul(newim,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(325);

plot(nx,ny);

title('PDF2- Histogram of Image 2');xlabel('grayscale level');ylabel('frequency');

subplot(326);

plot(nx,ccy)

title('CDF of Image 2');

xs2sgif(0,’figure1.gif’);


No comments:

Post a Comment