Tuesday, July 1, 2008

Activity 4

Image Enhancement by Histogram Manipulation


The image to be enhanced: a too-dark, 256 x 192 pixel, grayscale image of the viewing portal of the Magnetic Sheet Plasma Negative Ion Source of the Plasma Physics Laboratory.

The enhancement process:


im=imread('C:/Documents and Settings/Endura/My Documents/pls.jpg');
getf('imagehist.sce');

[x,y]=histogram(im);
plot(x,y);


This first part of the scilab program reads the above image and calls the histogram function from the 'imagehist.sce' file emailed by Ed David, then plots the below grayscale histogram:
As is obvious from looking at the original image, and now from the histogram, that it is a "poor contrast" image.

z=cumsum(y);

n=max(z);
z=z/n;
plot(x,z);


Once the histogram is normalized, it becomes the probability distribution function (PDF) of the image, and the above lines take the cumulative distribution function (CDF) from the PDF and plots the following graph:
The CDF graph has a steep initial increase but approaches unity slowly after the peak.

**when desired CDF is of a uniform distribution, a straight increasing line:

a=[0:1:255];

b=[0:1/255:1];

plot(a,b);
i=interp1(x,z,im);

j=interp1(b,a,i);
imshow(j,[0 255]);

This plots the desired CDF which is:
And outputs the image with its original pixel values replaced with the corresponding pixel values of the desired CDF with the same y-axis value.
The new, "histogram equalized" image is this:
Getting the CDF of the new, enhanced image using the first part of the program we get:


It looks distorted compared to the original image because the backprojection was done in discrete values.









**when the desired CDF mimics a given function,
like the given G(z)=tanh(k*(z-128)/255), where k is a constant. (in this report k=16)

...using the same starting lines as above to read the image, plot the PDF and CDF...

a=[0:1:255];
b=tanh(16.*((a-128)./255));
plot(a,b);
i=interp1(x,z,im);
j=interp1(b,a,i);
imshow(j,[0 255]);

gives the desired CDF:
and outputs the enhanced image:(Due to the encoding processes involved in exporting and uploading the image here, the above image is of decreased quality as compared to the actual image outputted by scilab)

  • i give myself a grade of 10 for this activity because i was able to successfully enhance the image both into a histogram equalized image and an image with a CDF that mimics the tanh function.
  • thank you to jeric and ed for the very, very useful programming tips, especially the histogram function.



No comments: