Activity 4: Image Enhancement

June 26, 2008 at 11:27 am (Uncategorized) (, , )

This activity enhances images by stretching the histogram of pixel values and stretching it in such a way that the maximum is 255 and the minimum is 0. another requirement is that the image cumulative distribution function (cdf) of the pixel values becomes linear. i wrote here a simple imhist function that can be included in the directory of the source code, and calle using getf(“imhist.sce”).

here is the source code of the “imhist.sce” function i wrote:

function [val,num]=imhist(im)
val=[];
num=[];
counter=1;
for i=0:1:255
[x,y]=find(im==i); //finds where im==i
val(counter)=i;
num(counter)=length(x); //find how many pixels of im have value of i
counter=counter+1;
end
return val, num;

-oOo-

after obtaining the probability distribution function (pdf, which is a normalized histogram), we obtain the cumulative distribution function.

taken from: http://home.earthlink.net/~rogergoodman/XRay-2000-06-05-Modabber.jpg

The probability distribution function and the cumulative distribution function

image enhancement is obtained by obtaining the the values of each pixel and backprojecting. in a sense, we are simple mapping each pixel of the original image to a new array with the CDF as the mapping function.

here is the code, which implemented my own imhist function. the “imhist.sce” file is loaded within the same directory as the program below.

-oOo-

//Jeric Tugaff
//Image Enahancement

clear all;
getf(“imhist.sce”);
im=imread(“aram.jpg”); //opens a 24 bit image
im=im*255;
[val, num]=imhist(im);
[sx, sy]=size(im);
num=num/(sx*sy);
normval=val/max(val);
cumnum=cumsum(num)/max(cumsum(num));
h=scf(1);
plot(normval, num);
h=scf(2);
plot(normval, cumnum);

enhanced=[];
im=im/255;
for i=1:sx
for j=1:sy
enhanced(i,j)=cumnum(find(normval==im(i,j)));
end
end
imwrite(enhanced, “enhanced.jpg”);
enhanced=round(enhanced*255);

//hist ulit
[val, num]=imhist(enhanced);
num=num/(sx*sy);
normval=val/max(val);
cumnum=cumsum(num)/max(cumsum(num));
h=scf(3);
plot(normval, num);
h=scf(4);
plot(normval, cumnum);

-oOo-

Using any non-linear CDF

Using any non-liner CDF, we produced better images than backprojecting along a linear CDF. The flowchart of the pixel backprojecting is summarized by this image from Dr. Soriano’s lecture.

Enhanced Image using parabolic CDF

Actual and desired parabolic CDF

Again, there is good (not perfect) correspondence with the desired (smooth) and actual (jagged) CDF. Here is my code, which is quite slow but is more general especially when in cases where the inverse function of the CDF is difficult to solve analytically:

//Jeric Tugaff
//Image enhancement using parabolic CDF

clear all;
getf(“imhist.sce”);
im=imread(“aram.jpg”); //opens a 24 bit image
im=im*255;
[val, num]=imhist(im);
[sx, sy]=size(im);
num=num/(sx*sy);
normval=val/max(val);
cumnum=cumsum(num)/max(cumsum(num));
h=scf(0);
plot(val, num)

enhanced=[];
desired_cdfx=[0:1:255];
desired_cdfy=desired_cdfx.*desired_cdfx;
desired_cdfy=desired_cdfy/max(desired_cdfy);

for i=1:sx
for j=1:sy
step2(i, j)=cumnum(im(i,j));
end
end

enhanced=interp1(desired_cdfy, desired_cdfx, step2);
h=scf(1);
imshow(enhanced, [0 255]);
enhanced=round(enhanced);
//hist ulit
[val, num]=imhist(enhanced);
num=num/(sx*sy);
normval=val/max(val);
cumnum=cumsum(num)/max(cumsum(num));
h=scf(3);
plot(val, cumnum);

-oOo-

collaborators: julie, lei, cole

rating: 10, because i’ve been able to implement my own imhist function and the resulting cumulative disctribution is has good correspondence with the desired CDF. 🙂

Permalink Leave a Comment