Monday, June 30, 2008

Enhancement by Histogram Manipulation

In this activity, we enhanced a poor contrast grayscale image by manipulating its histogram. To do this, I first get a histogram of the poor contrast image.










Image taken from http://www.onlinetelemedicine.com/html/product/sam_images/X-Ray.jpg

As we can see in this histogram, the pixel values do not occupy the whole grayscale range(0-255). Instead, it is limited only the middle values of the grayscale, specifically 3-175.
To enhance this image, I need to backproject the image using the CDF of its histogram. The CDF of the image is shown below.
The CDF is almost a straight line, but the range is only from 3-175. The backprojection was done as follows. For each pixel value, I would look up its corresponding y value in the CDF.

//SCILAB Code
imsize = size(image);

cy = cumsum(y);

cy = cy/max(cy); //normalized CDF y-value
for i = 1:imsize(1)
for j = 1:imsize(2)

index = find(x == image(i, j));
image(i,j) = cy(index);
end
end

//code end

After the backprojection, the image and its CDF are transformed as seen below.












The image after backprojection has a much better contrast and its CDF now looks like a straight line which extends from 0-255.

The next part of this activity was to use a nonlinear CDF to backproject the image. The main steps to do this was from x1(original value of the pixel), we find its corresponding y in its CDF (y1). y1 is then traced to the desired CDF (y2). And lastly, find the corresponding x value of y2 (x2).
The left image is the original image and the right image is a tanh function.

//Scilab Code
imsize = size(image);
cy = cumsum(y);

cy = cy/max(cy);

scf(1);

plot(x, cy)
x = 0:255;

G = tanh(16.*(x-128)./255);

G = (G - min(G))./2;

scf(2);
plot(x, G)

for i = 1:imsize(1)

for j = 1:imsize(2)
index = find(x == image(i, j));

y1 = cy(index);

index2 = find(G <= y1);
image(i, j) = x(index2(max(index2)));

end

end

//code end

After the backprojection, the image and its CDF becomes:












The new CDF follows the tanh function.

For this activity I grade myself 10 because I was able to perform the required task and I worked independently.

No comments: