Tuesday, June 23, 2009

Image types and basic image enhancement

Shown below are the examples of the different types of images with their corresponding properties.


Figure1. True Image
Image Properties:
Truecolor Image
FileName: true color.jpg
FileSize: 178712
Format: JPEG
Width: 411
Height: 500
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 72.000000
YResolution: 72.000000


Figure2. Indexed Image
Indexed Image
FileName: index_m.jpg
FileSize: 10590
Format: PNG
Width: 174
Height: 200
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000



Figure3. Grayscale Image

Size: 257 rows X 200 columns
Indexed Image
FileName: 200px-Breadfruit.jpg
FileSize: 9272
Format: JPEG
Width: 200
Height: 257
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: inch
XResolution: 100.000000
YResolution: 100.000000


Figure 4. Binary Image
Size: 352 rows X 353 columns
Indexed Image
FileName: Leopard_bw.bmp
FileSize: 16960
Format: BMP
Width: 353
Height: 352
Depth: 8
StorageType: indexed
NumberOfColors: 2
ResolutionUnit: centimeter
XResolution: 118.080000
YResolution: 118.080000

The scanned image I chose was converted to grayscale type using GIMP software. Here, the histogram is taken also by using GIMP. These are shown in the figures below:



Notice from the histogram that all graylevels (0-255) are well distributed. Thus, we can say that the region of interest (ROI) is well separated from the background.
After this, the image was again converted to binary type with threshold level of 0.4. This seems to be the best threshold since it still shows similar information of the image. From the code generated to find the area of several polygons in Activity 2, the area of the image was calculated.The theoretical value of the area was taken by counting the number of pixels in the binary image. This was done by summing up all the 1's in the image, since the pixel values are only 1 and 0.




The 9% error can be attributed to the curved contour of the image that was not included upon performing the formula in the Green's theorem.

The histogram for the grayscale image can also be done using Scilab. The following code shows how:
//histogram
hist=[];
counter=1;
for i=1:256;
num=find(scanimg==i);
hist(counter)=length(num);
counter=counter+1;
end;

Notice the high correlation between the histogram from GIMP and Scilab. This means that the code is correct.

In this activity, I am giving myself a grade of 10 since all the tasks have been done with pretty good results.

References for the images:
true image: http://farm4.static.flickr.com/3272/2789704173_3bbc22342b.jpg

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

grayscale image: http://en.wikipedia.org/wiki/Black-and-white

binary image: http://www.scouting.org.za/clipart/badges/cubadvancement/Leopard_bw.bmp

Monday, June 22, 2009

Area Estimation for Images with Defined Edges


Figure 1. Binary Image of a rectangle


Figure 2. Binary Image of a Circle


Figure 3. Binary image of a triangle

In this activity, the first thing I did was draw a rectangle, circle and triangle using Paint. These figures shown above are saved in JPG format. Next, I opened Scilab 4.1.2 and imported all these images. The image type of the figures is true color, so I converted them to binary type using the command “im2bw”. From the SIP toolbox downloaded and installed, I utilized “follow” command in order to generate the contour and obtain the pixel values of the edges. The figures below are the generated contours of the images.








Using Green’s Theorem, the area was computed. This was done by following the formula:


The corresponding code I made for this equation is:

image1=imread('binary image.jpg');
bw1=im2bw(image1,0.5);
[x1,y1]=follow(bw1);
Al=[];
for i=1:length(x1)-1;
A1(i)=(x1(i)*y1(i+1))-(y1(i)*x1(i+1));
end
area1=(sum(A1)*0.5)

Basically, I sum up all the values generated from the distance between two contour points and divide them by 2. The value in “area1” shows the area of the polygon. To check if the measured area was reliable, I compared it with the theoretical value which was generated by counting all the 1’s in the binary type image. Since the corresponding value of each pixel in the images are just 1 and zero, with 1 corresponding to the area polygon, by summing all 1’s, we can get the area. The table below shows the theoretical and calculated values of the areas of each polygon and the % error.



The deviation of the calculated area from the theoretical value is small and is ~2%, which means that Green’s Theorem is accurate and precise in area measurement. The errors are attributed to the boundary of the figures (contour lines) which are not considered in the formula I used. The computation can be made more accurate by considering this boundary. Either add the contour line in the Green's formula or subtract it from the pixel count of the image.


I would like to acknowledge Mr. Gilbert Gubatan, Gary Garcia and Orly Tarun for giving wonderful insights regarding this activity. And of course, to Dr. Soriano for assisting us and giving us some tips on area calculation. Thank you!
In this activity, I give myself a 9 to account for the % error.

Wednesday, June 17, 2009

Digital Scanning







In this activity, replication of the image of a graph was performed by relating the pixel locations and physical values of the data points. By using Paint, the scanned image of the graph showing the number of observed asteroids (in logarithmic form) with brightness from 9.0 (magnitude) from the book entitled “The System of Minor Planets” by Gunter D. Roth (1962) was opened. The tick marks were recorded as well as their pixel locations. The x-axis which corresponds to the brightness of asteroids began at 9 and end to 17 with an increment of 1. On the other hand, the y-axis of the graph which shows the number of asteroids in logarithmic form started from 0 up to 3.5 with an increment of 0.5. Since the increments in each axis are equal, the difference between the pixel locations of the tick marks must also be the same. However, there are small deviations from what I got using Paint. So, I took the average of the differences of the pixel locations of the tick marks in the x and y axes, noting that for the horizontal axis, the y-coordinates are the same and in the vertical axis, the x-coordinates are equal. The average values for x and y-axis are 72.57 and 74.17, respectively. The ratio between the increment of the physical value of the tick marks and their averaged pixel location difference were taken. This was used to measure the physical value of the points in the graph given their pixel locations.

For the physical value of the data points along the x-axis, the pixel location of each point was subtracted to the x-axis pixel location of (9, 0) since it is the starting point in the horizontal axis. This was then multiplied with the ratio obtained. Finally, 9 was added from the product to account for the starting point of the x-axis. Similar procedure was done to obtain the physical value of the points in the y-axis. However, it must be reminded that in Paint software, the value of the y-axis increases as we go downward (opposite of that in the graph). So, the y-coordinate pixel location of the starting point (9, 0) was subtracted to the pixel location of the point and then multiplied with the ratio obtained. All this computations were done using Microsoft Excel 2007.

The physical x and y values of the data points in the graph were then plotted in Excel. To check whether the obtained physical values matched with that in the scanned image of the graph, the image was overlaid from the plot. This was done by right clicking the plot and choosing “Format Plot Area”. From the dialog box, go to “Fill” and click “Picture of texture fill”. Then, insert the image from the File and then close the dialog box. The scanned image must be cropped properly such that only the graph is being shown for accurate comparison with the reconstructed plot. The last figure shows the scanned image overlaid with the reconstructed plot. It can be seen that the calculated physical values of the data points matched almost perfectly with that from the image.

I would like to acknowledge Mr. Jay Samuel Combinido for giving helpful suggestions in improving my plot and our teachers, Dr. Soriano and Dr. Perez for their assistance. For this activity, I give myself a grade of 8 because there is still very small difference between the scanned image and the reconstructed one.