stacksize(100000000);
PATH = 'C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 5\';
//PATH = 'C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 5\images\';
filename = 'cousins';
imagefile = strcat([PATH,filename,'.jpg']);
I = gray_imread(imagefile);
//imwrite(I,strcat([PATH,'cousins_gray.bmp']));Figure 1. A dark image taken by a Digital SLR
Figure 1 shows a dark looking image. The image was imported in Scilab using the gray_imread() function. The grayscale histogram of the image was tabulated and plotted as shown in Figure 2. The PDF of the image was determined by normalizing the histogram, that is, dividing by the total number of pixels. Afterwhich, the CDF was determined from the PDF. This was done by performing a cumulative sum on the frequencies of the graylevel. Figures 3 and 4 shows the PDF and CDF of the image, respectively.
//plot the histogram of the grayscale image
scf(0); histplot(256,I);
title('Histogram of a grayscale image');
xlabel('grayscale value'); ylabel('frequency');
xs2bmp(0,strcat([PATH,'histplot.bmp'])); //sends the graphics into a file
//tabulate the grayscale values
[H] = tabul(I,"i");
gs = H(:,1); //saves the grayscale value
f = H(:,2); //saves the frequency for each gray level
scf(1); plot(gs,f);
title('Histogram of a grayscale image');
xlabel('grayscale value'); ylabel('frequency');
xs2bmp(1,strcat([PATH,'histogram.bmp'])); //sends the graphics into a file
//calculating the Probability Distribution Function (PDF)
pdf = f/sum(f); //normalize
scf(2); plot(gs,pdf);
title('PDF (normalized histogram) of a grayscale image');//histogram plot of the grayscale image
xlabel('grayscale value'); ylabel('frequency');
xs2bmp(2,strcat([PATH,'pdf.bmp'])); //sends the graphics into a file
//calculating the Cumulative Distribution Function (CDF)
F = cumsum(pdf); //cumulative sum of the frequency
cdf = F/max(F);
scf(3); plot(gs,cdf); //cumulative sum plot of the pdf plot
title('CDF of the PDF of the grayscale image');
xlabel('grayscale value'); ylabel('frequency');
xs2bmp(3,strcat([PATH,'cdf.bmp'])); //sends the graphics into a file
Figure 2. Histogram of the grayscale image.
Figure 3. The probability distribution function (PDF) of the grayscale image.
Figure 4. The Cumulative distribution function (CDF) determined from the PDF.
In this activity, I used three different CDF, namely uniform distribution (linear), parabolic and logarithmic. For each CDF, the x-axis is the range of grayscale values of the original untreated image [0-1] and the y-axis is equal to the value of the defined function (linear, parabolic or logarithmic).
//Pixel-per-Backprojection
[r,c] = size(I);
for i = 1:r
for j = 1:c
n = find(gs==I(i,j)); //index
N = cdf(n,1); //value on the index
M = 255*N; //uniform
// M = exp(N); //logarithmic
// M = -sqrt(N); //parabolic
I(i,j) = M;
end
end
I = (I - min(I))/(max(I)-min(I));
imwrite(I,strcat([PATH,filename,'_parabolic.bmp']));
Figure 5. Modified image using a linear CDF.
Figure 6. Modified image using a parabolic CDF.
The histogram manipulation was done pixel-per-pixel, backprojecting the image pixel values by looking for its corresponding y-value in the desired CDF. This is the same as replacing the dark pixel values with the x-values from the desired CDF. Figure 5-7 show the three modified images using three different desired CDF. The histogram and the CDF of the modified images are shown in Figure 8-10. The CDFs shown are equivalent to those previously desired.
Figure 8. The (a) histogram and (b) CDF of the image in Figure 5.
Figure 10. The (a) histogram and (b) CDF of the image in Figure 7.
I also tried using the histogram manipulation that can be found in advanced image processing software such as Photoshop or GIMP. I opened the same image in the GIMP and converted it to a grayscale image. Using the Curves function, the histogram CDF was manipulated by simply dragging the diagonal line to a desired position. Figure 11 shows the original image and its histogram. Figure 12 shows the images modified by manipulating the histogram.
Figure 11. Original image with its histogram opened in GIMP.
No comments:
Post a Comment