Monday, June 30, 2008

Activity 4 - Enhancement by Histogram Manipulation


I wanted to apply what I learned during the class about improving the contrast so I used an image of a sample seen under a microscope. The image above is the original image.

Max grayscale pixel value = 103

Min grayscale pixel value = 17


Above is the histogram of the original image. We can see that it has only a limited range of grayscale values which means the image is of poor contrast.

The Cumulative Distribution Function (CDF) is shown above. The CDF is not linear and has a point of saturation where the value becomes 1 which is the highest value of the CDF

We backproject the image pixel values by finding its corresponding y-value in the CDF. That is, replace the pixel value by the values on the y-axis of the pixel value from the CDF. The resulting image is called the histogram equalized image. The histogram equalized image is shown below.


We could see visually that the contrast was improved. We verify this by looking at its histogram. The histogram is shown below.

The histogram is well spread which means that the image has good contrast. Comparing it to the original image, the contrast of the histogram equalized image is far much better. The CDf is shown below and it can be seen that it is linear.

I used another method to improve the contrast of my image. I stretched my CDF and in the process also stretched the range of grayscale values that are present. The resulting image, its histogram and CDF is shown below.


At the last part of the activity we transformed the image to have a desired CDF. The desired CDF equation has the equation G=tanh(16*(z-128)/255). But since the values must be from zero to one then we normalize the equation by adding one then dividing it by the maximum value. I did that on scilab and I get the CDF below.


Now we use the algorithm

1. From the pixel grayscale, find CDF value.

2.Trace this value in the desired CDF.

3.Replace pixel value by grayscale value having this CDF value in desired CDF.

The resulting image is shown below.


The CDF of this new image is shown below.

I could say it almost fits perfectly to the desired CDF. The histogram of this new image is shown below.

As we could see, the histogram shows that it has a poor contrast which is evident in the image seen. And also, some details are not conducive for human eyes

These are all the images in the following order: original, histogram equalized, stretched histogram, desired cdf)



I also used an image from mathworks.com




I would like to thank Eduardo David for the faster way of getting the histogram and cumulative some. Also for Rafael Jaculbia for some help in the understanding of CDF. I would rate my self 10 out 10 for this activity since I have successfully transformed my image to match the CDF that we want. I want to still try many other CDF but it would take so much of time and space.


image source:http://www.mathworks.com/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox/images/imadjust.html

Thursday, June 26, 2008

Activity 3 – Image types and basic image enhancement





These are the information of the images above given by the command imfinfo in scilab.

Binary Image

Grayscale Image

FileName: binary.png

FileName: grayscale.png

FileSize: 2660

FileSize: 90505

Format: PNG

Format: PNG

Width: 200

Width: 420

Height: 140

Height: 320

Depth: 8

Depth: 8

StorageType: indexed

StorageType: indexed

NumberOfColors: 2

NumberOfColors: 256

ResolutionUnit: centimeter

ResolutionUnit: centimeter

XResolution: 72.000000

XResolution: 72.000000

YResolution: 72.000000

YResolution: 72.000000


Indexed Image

Truecolor Image

FileName: indexed.png

FileName: truecolor.jpg

FileSize: 25576

FileSize: 4812

Format: PNG

Format: JPEG

Width: 150

Width: 104

Height: 200

Height: 145

Depth: 8

Depth: 8

StorageType: indexed

StorageType: truecolor

NumberOfColors: 256

NumberOfColors: 0

ResolutionUnit: centimeter

ResolutionUnit: centimeter

XResolution: 72.000000

XResolution: 72.000000

YResolution: 72.000000

YResolution: 72.000000

FileSize: 46050

Format: JPEG

Width: 179

Height: 274

Depth: 8

StorageType: indexed

NumberOfColors: 256

ResolutionUnit: inch

XResolution: 96.000000

YResolution: 96.000000

The histogram of my scanned image is shown below. It can be seen that the histogram is quite spread meaning that the image has a good contrast. Also, we see that the image is well separated from the background because we could see a valley. Thank you for Jeric Pineda and Eduardo David for the help with the scilab code.



The scanned image is converted to a binary image by the command im2bw in scilab. We used the program we made in the previous activity and calculate the area of our scanned image. I also used paint to estimate the area of my scanned image.

Using the program made during the previous activity that uses Green’s theorem we obtained an area of 40376 square pixels. Using paint I estimated the area to be 40320 square pixels. Since my image is almost a perfect rectangle I just multiplied the length (252 pixels) by the width (160 pixels) to approximate the area of the scanned image. We see that the calculated area’s are almost the same which means that our method for computing the area using Green’s theorem is applicable.

I rate myself 10 out of 10 since I have successfully plotted the histogram of my scanned grayscale image and I have shown that the calculated area using Green’s theorem is close, if not equal, to the actual pixel area of the scanned image.

Colaborators: Eduardo David, Jeric Pineda, Rafael Jaculbia\

Sources of Image:

binary:http://en.wikipedia.org/wiki/Binary_image

grayscale:http://weblogs.java.net/blog/kirillcool/archive/2007/04/non_photorealis_1.html

indexed:http://en.wikipedia.org/wiki/Indexed_color

Wednesday, June 18, 2008

Area Estimation






For this activity we used scilab with siptoolbox to read images we have drawn.
The dimensions of the drawn images are known.
I have drawn the following images which are shown above:
Square(side = 214 pixels)
Circle(diameter = 157 pixels)
Triangle(base = height = 214)
Rectangle(118 pixels * 158 pixels)

Using the imread function, an image is converted to a binary matrix. Then using the follow function, the coordinates of the borders were obtained. Using the green's formula we could approximate the area of the image. Green's formula is shown above.
The code in scilab is shown below.

------------------------------------------------------------------------------------------------
A=imread('name of file');
[x,y]=follow(A);
x1=x;
y1=y;
x1(1)=x(size(x,'r'));
x1(2:size(x,'r'))=x(1:(size(x,'r')-1));
y1(1)=y(size(y,'r'));
y1(2:size(y,'r'))=y(1:(size(y,'r')-1));
X=x.*y1;
Y=y.*x1;
Area=0.5*(sum(X)-sum(Y))
------------------------------------------------------------------------------------------------

Calculated by Green's equation Calculated Using Dimensions %error
(pixel*pixel) (pixel*pixel)
Square 45796 45796 0
Circle 19508 19359 0.769667855
Triangle 22684.5 22898 0.932395842
Rectangle 18644 18644 0


Collaborators: Rafael Jaculbia, Eduardo David

I rate myself 10 out of 10 since I have successfully used Green's formula to estimate the area of the images and compared it to the areas calculated using the formulas for area of basic shapes. It is seen that there are no error's in square and rectangle shapes. This is because the pixels fit perfectly to the shapes since they are squares. Perfect circles, on the other hand, cannot be created through pixels. This is also true for shapes with diagonals like the triangle.

Wednesday, June 11, 2008

Activity 1


These are the data that I have gathered in the activity. I would rate myself 10 in reconstructing the graph since I have successfully overlapped my graph to the scanned graph. Also, I have done the necessary steps in order to calculate the pixels per unit of both the x-axis and the y-axis. Using this conversion I can convert the number of units(pixels) by multiplying(dividing) the number of pixels(units) obtained.
x(pixel location) y(pixel location) y-axis pixel between ticks

67 506 0


67 443 100 63

67 380 200 63

66 317 300 63

66 255 400 62

66 186 500 69

65 130 600 56

65 67 700 63



average 62.71428571



pixels per unit 0.627142857

x(pixel location) y(pixel location) x-axis pixel between ticks

67 506 0


98 506 5 31

129 506 10 31

160 506 15 31

191 506 20 31



average 31



pixels per unit 6.2













Origin(pixel location)
67 506


x pixels per unit 6.2



y pixels per unit 0.627142857



x(pixel location) y(pixel location) x pixels from origin y pixels from origin x equivalent unit y equivalent unit
93 406 26 100 4.193548387 159.453303
117 307 50 199 8.064516129 317.3120729
134 266 67 240 10.80645161 382.6879271
177 186 110 320 17.74193548 510.2505695
177 60 110 446 17.74193548 711.1617312
83 443 16 63 2.580645161 100.4555809
83 443 16 63 2.580645161 100.4555809
99 386 32 120 5.161290323 191.3439636
115 324 48 182 7.741935484 290.2050114
131 276 64 230 10.32258065 366.7425968
147 239 80 267 12.90322581 425.7403189
163 208 96 298 15.48387097 475.1708428
177 161 110 345 17.74193548 550.1138952
177 136 110 370 17.74193548 589.977221
177 111 110 395 17.74193548 629.8405467
177 86 110 420 17.74193548 669.7038724