Wednesday, June 24, 2009

Activity 2: Area Estimation for Images with Defined Edges

To compute for the area of arbitrary binary images, we will make use of Green's theorem. The test images are as follow

Figure 1. Rectangle with dimension190x115


Figure 2. Ellipse which can be enclosed in a rectangle of dimension 200x100

Figure 3. Irregular shape.

Figure 4. Image containing two contours.

The results are as follows

Table 1. Summary of results.
The results from the sum() function serves as the theoretical value since it literally gives area of the white region (in pixels) of a binary image. For shapes with a single continuous contour, sum() and Green's theorem methods are in agreement. Green's theorem fails with shapes having two contours as with figure 4. Below is the code used for this activity

//Scilab code. Special thanks to Miguel Sison for figuring out how to run the SIP toolbox.

chdir('C:\Users\Mark Jayson\Documents\Physics\APhysics 186\Act 2');
//read image
I=imread('ireg.png');

I=im2bw(I,0.5);

[x,y]=follow(I);

temp=0;

for i=1:length(x)-1
temp=temp+(x(i)*y(i+1)-x(i+1)*y(i));
end

temp=temp+(x(length(x))*y(1)-x(1)*y(length(y)));

A=0.5*(temp+length(x))+1 //the length(x) term is necessary to include the contour itself in the area calculation. Plus 1 is need to close the contour.

theo=sum(sum(I))

er=(A-theo)/theo

For this activity I'll give myself a 9.0. I posted it a little late because I have to figure out what went wrong to my initial code. ^_^

Monday, June 22, 2009

Activity 3: Image Types and Basic Image Enhancement

Below are the different types of images. Images information are found using Scilab's SIP toolbox function imfinfo

Binary Image
FileName: 37081406.gif
FileSize: 15054
Format: GIF
Width: 500
Height: 461
Depth: 8
StorageType: indexed
NumberOfColors: 2
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000

Source:http://www.nisk.k12.ny.us/fdr/ideas/portfolio/vandersee/gifs/37081406.GIF


Grayscale Image
FileName: lena512.bmp
FileSize: 263222
Format: BMP
Width: 512
Height: 512
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 0.000000
YResolution: 0.000000

Source: http://www-ece.rice.edu/~wakin/images/lena512.bmp



Indexed Image
FileName: imgcolor16.gif
FileSize: 27065
Format: GIF
Width: 248
Height: 248
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: centimeter
XResolution: 72.000000
YResolution: 72.000000

Source: http://idlastro.gsfc.nasa.gov/idl_html_help/images/imgcolor16.gif


Truecolor Image
FileName: mandrill.jpg
FileSize: 327564
Format: JPEG
Width: 500
Height: 480
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 96.000000
YResolution: 96.000000

Source: http://www.cs.uwec.edu/~stevende/cs245/labs/lab08-Threads/mandrill.jpg

Note that binary and grayscale images are also indexed images. The difference is that in binary images, there are only two colors (black and white) and in grayscale images there are 256 colors of different levels of gray.

Monday, June 15, 2009

Activity 1: Digital Scanning

Introduction
In this activity, ratio and proportion was used to find the numerical values of a digitally scanned plot. (See figure 1.)

The numerical values were deduced from the pixel locations of the plot given as x- and y-coordinates. MS Paint was used to find the pixel locations which were then tabulated in OpenOffice Calc.

Since we are dealing images, the coordinate axes is a bit different in the traditional sense. The origin (i.e. pixel location (0,0)) is located at the upper left corner of the image and the positive y-axis is reversed. he origin of the plot is at some pixel location (h, k). For simplicity, h is subtracted from the pixel locations along x and k is subtracted from the pixel locations along y

xnew = xi - h
ynew = -
(yi - k)

Note that the negative sign for the y pixel location comes from the fact that the y-axis for images is reversed (refer to figure 2).

After translating the axes, the ratio for converting pixel values to actual values is computed. This was done by counting the number of pixels between tick marks on the plot and noting the corresponding increment size in the actual values. Along the horizontal, a pixel difference of 76 was found for each 5 deg C increment. Along the vertical, a pixel difference of 117 was found for each 0.001 increment. Thus the computed ratios are

ratiox=actual diff/pixel diff = 5/76 = 0.066
ratioy=actual diff/pixel diff = 0.001/117 = 0.000009


Therefore the actual values are

xactual = xnew*ratiox
yactual = ynew*rati
oy

For the plot that i've chosen, it is necessary to add 1.0 to the y values since the y-axis does not start at zero but rather at 1.0. The reconstructed plot is as follow


To compare the original plot with the reonstructed one, the former was set as a background for the latter. As with figure 3, the reconstruction is quite satisfactory.

OpenOffice Calc: Adding an image in the chart wall


To add an image in a
n OpenOffice Calc chart, the first thing to do is add the desired image to bitmap list of Calc
1. Select the chart then click Format -> Graphics -> Area
2. Click the Bitmap tab then click Import.
3. Select the image that you want.
4. Save the list.
5. You need to restart Calc before you can use the newly added image. Be sure to save your work first. (thanks to Janno)

Once your done, you may
6. Right-click on the chart and then select Chart Wall.
7. Click on the Area tab and in the pull-down menu select Bitmap. Your image should be there.
8. Set it to Stretch to fit.
9. Click Ok and your done. You may also want to check the scale of your axes.


For this activity I'll give myself a 9.0. ^_^

[1] Kimball, A. (1911). College Textbook of Physics. Henry Holt and Company.