Images with low contrast may be enhanced by manipulating its histogram. This post on my blog will show you just that.
(Histogram is a graph showing how many pixels have a particular value, from 0-255, in a grayscale image. This is equal to the probability distribution function or PDF.)
Start with an image that you want to enhance:
(Histogram is a graph showing how many pixels have a particular value, from 0-255, in a grayscale image. This is equal to the probability distribution function or PDF.)
Start with an image that you want to enhance:
Convert this image into grayscale:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6o-xdWbcQHeq6wBT-smAXl2Eq6NMujuwkt7XbUQVYg3HStYcAU3M_toZN844Pu90rUhpkypIKdSC0r2tXY5GZiTgknL4r1mkAgT9WPySYzFDVI2paa_d-uU1ZTFL-pdYTCYIeYhfxOIuH/s400/histogramn.bmp)
From the obtained histogram, get the CDF(cumulative probability function) using the scilab fuction cumsum():
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSf87vWN-EVKg8dezQxeSZzGDk2_ogySt2b8lbz_AbW1ze2513jlZ76eHDJIzmoNboV2kABRG6Ha_24FvthFts1pnctzpwwgD9CkMoFPyAucajxlhvhgfINzo7icVwfsOQeFxCMkDqYIXv/s400/desiredn.bmp)
By pixel-per-pixel backprojection, the undesired pixels may be replaced with the x-values of the desired CDF. The image below shows the modified image. If compared with the original image, this one is clearer and more resolved.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDLb66vvEyo8dXguO7npbJugHf_qB1VjBaCoBNgjMX2-RhF74Z7ghKtM9lIvykTuWd0StmpvdLjhOSbyHd624yiuJlQ0cVzhLbGoruJL6vA_ZuvrYrBqe1iUvau6OoISz18l4j-hWLL3_x/s400/spline.bmp)
Other softwares such as photoshop and GIMP allows you to "twick" your image's histogram. As a comparison, I also tried manipulating my original image's histogram in imagej. The results are shown below:
Using imagej:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV0hgKCirl2MqJAvi5geItdkt_pHiWdVenmVMWWjQYLiO_ERHJ6_oU8kYN6gvgfSP8ng-EMx1vLDeUxdGMyvYUPat0MA0xorw28THKsfTv4XM5JhC1u_0ECs1jte-Payb_0zsaDbUZ6f2f/s400/imagej.bmp)
CODE:
//reading the image
I = gray_imread('C:\Users\cindyleen\Desktop\DSC03137.jpg');
scf();
//imshow(I);
//PLOTTING THE HISTOGRAM OF THE IMAGE
histplot(256,I);
//TABULATION OF FREQUENCY PER GRAYSCALE VALUE(0-256)
tab = tabul(I, 'i');
x = tab(:,1);
y = tab(:,2)/sum(tab(:,2)); //normalization of frequency
//disp(sum(y))
//scf();
//plot(x, y, '.')
//getting the CDF
ycum = cumsum(y);
scf();
plot(x, ycum) //this is the CDF of your image
//desired CDF(linear)
scf();
plot(x,x)
//BACKPROJECTION
[r c] = size(I);
ix = I(:);
yp = interp1(x,ycum,ix);
xd = interp1(x,x,yp,['spline']);
//displaying the processed image
Inew = matrix(xd, [r c]);
scf();
imshow(Inew);
I would to give my self a grade of 9.5 for this activity. Although I did manage to get all output ask, I'm afraid I wasn't able to explain the method clearly in this blog.
Thank you Joseph for all the help in this activity! :D
//reading the image
I = gray_imread('C:\Users\cindyleen\Desktop\DSC03137.jpg');
scf();
//imshow(I);
//PLOTTING THE HISTOGRAM OF THE IMAGE
histplot(256,I);
//TABULATION OF FREQUENCY PER GRAYSCALE VALUE(0-256)
tab = tabul(I, 'i');
x = tab(:,1);
y = tab(:,2)/sum(tab(:,2)); //normalization of frequency
//disp(sum(y))
//scf();
//plot(x, y, '.')
//getting the CDF
ycum = cumsum(y);
scf();
plot(x, ycum) //this is the CDF of your image
//desired CDF(linear)
scf();
plot(x,x)
//BACKPROJECTION
[r c] = size(I);
ix = I(:);
yp = interp1(x,ycum,ix);
xd = interp1(x,x,yp,['spline']);
//displaying the processed image
Inew = matrix(xd, [r c]);
scf();
imshow(Inew);
I would to give my self a grade of 9.5 for this activity. Although I did manage to get all output ask, I'm afraid I wasn't able to explain the method clearly in this blog.
Thank you Joseph for all the help in this activity! :D
No comments:
Post a Comment