Thursday, June 26, 2008
Activity 3: Image Types and Basic Image Enhancements
I. Image Types

Browsing the Internet I found interesting True color and Indexed images of butterflies. For the True color image and using "imfinfo" to analyze it:

we get the data:
FileName: butterfly.JPG
FileSize: 19799
Format: JPEG
Width: 300
Height: 270
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 300.000000
YResolution: 300.000000

image from (www.oodleoodle.com)

While for the indexed image which is in grayscale and having bit depth of 8 (ie. colored bit depth is 24 since we would have 8+8+8) we get the data: FileName: butterflybw1.JPG
FileSize: 152433
Format: JPEG
Width: 1200
Height: 1200
Depth: 8
StorageType: indexed
NumberOfColors: 256
ResolutionUnit: inch
XResolution: 300.000000
YResolution: 300.000000

II. Histogram, Thresholding, and Application in Measuring Area

Using a scanned image of a door key, we get an image with properties:

FileName: key1.jpg
FileSize: 63561
Format: JPEG
Width: 967
Height: 819
Depth: 8
StorageType: truecolor
NumberOfColors: 0
ResolutionUnit: inch
XResolution: 300.000000
YResolution: 300.000000

Cropping the key and obtaining a histogram using Jeric's code in the AP186 Google groups (in the process of making a histogram the image is converted into grayscale, compare true image and grayscale image.):
True Image:
Gray scale Image:
Histogram:
From the histogram we observe two peaks and we are particularly interested in the first peak under the domain (0-150) since the second peak in the domain (150-255) is observably defined. In using "im2bw" of Scilab to convert the Gray scale image into binary, I used the threshold value of 110 giving a binary image:
Using Green's Theorem from Activity 2 we get an area value of 272542 pixel values while using pixel count we get an area value of 273043 pixel values which gives roughly only 0.18% error! Converting these data into centimeters we get: 13.76 cm^2 using Green's Theorem and 13.79 cm^2 through pixel counting.

Appendix:

A copy of the code I used:

For Histogram:

key=imread('key.JPG');
key=key(:,:,1);
imwrite(key(:,:), 'key gs.jpg'); //converts original image to 8 bit Gray scale image
key=imread('key gs.jpg');
val=[];
num=[];
counter=1;
for i=0:1:255
[x,y]=find(key==i); //finds where the image==i
val(counter)=i;
num(counter)=length(x); //finds how many pixels has with a value ==i
counter=counter+1;
end
plot(val, num); //gives the histogram

For Green's Theorem and Pixel Count

key=imread('key.JPG');
key=key(:,:,1);
imwrite(im(:,:), 'key gs.jpg'); //converts original image to 8 bit Gray scale image
key=imread('key gs.jpg');
key=im2bw(key, 110/255); //converts the Gray scale image into a Binary image
//key=1*(key==0); //inverts the image //unnecessary in this image's context
[x,y]=follow(key);
x1=[];
x1(1:length(x)-1)=x(2:length(x));
x1(length(x))=x(1);
y1=[];
y1(1:length(y)-1)=y(2:length(y));
y1(length(y))=y(1);
area=0.5*abs(sum(x1.*y-y1.*x)) //uses Green’s theorem
ta=0;
[sx, sy]=size(key); //uses rectangles to find the area
for i=1:sy
f=find(key(:, i)==1);
pixcount=pixcount+max(f)-min(f);
end
pixcount
err=(area-pixcount)/pixcount*100
Acknowledgments:

Thank you for Jeric, Beth, and JC for helping me out with this activity with the codes and their moral support (ie. "Kaya mo 'yan Paul!" Hahaha!). Because of the good result I had in acquiring the image area, I give myself 10/10 neutrinos.




posted by poy @ 11:49 PM   0 comments
Wednesday, June 18, 2008
Activity 2: Area Estimation for Images with Defined Edges
For this activity we first made two white shapes bordered by black background. I made a circle and a rectangle:


Manually, the area of the rectangle is 37824 pixel units since it is 192 x 197 pixel units. The circle's area on the other hand roughly (since there is an error made when making the circle on MS paint) has a diameter of 150 pixel units and therefore using the formula: Area of a circle is equal to pi multiplied to the square of the radius; we get 17671.455.

Using "follow" in Scilab to get the edged pixel values, and "size" to get [the size]. Implementing Green's theorem in Scilab the following values for the rectangle and square can be obtained respectively: 36864 pixel units and 15676 pixel units. Therefore the error for both tries are: 2.54% for the rectangle and 11.29% for the circle.

Thank you to Ed, Ma'am Jing for their patience in trying to help me install Scilab in my laptop (which I failed to do by the way) and for Marge and JC for helping me finish the activity. I give myself 9/10 neutrinos for this activity!
posted by poy @ 8:38 PM   1 comments
Thursday, June 12, 2008
Activity 1: Digital Scanning
For this activity, the first step is to acquire a digitally scanned image of a handwritten drawing of a graph from an old science journal:
The graph is a handsketched graph of the schematic frequency spectra of the simple cubic lattice in Mazur and Montroll's 1960 work entitled: Poincare Cycles, Ergodicity, andd irreversibility in Assemblies of Coupled Harmonic Oscillators.

The graph I obtained was tricky since it doesn’t have any tick marks to act as partition between points, save for markers indicating the ω’s. So what I did was to first obtain the origin’s pixel values and the borders of the x and y axes, divide it by 100, in order to obtain the corresponding points. No scaling needs to be done, only translating the axis therefore the pixel values of the origin was all I needed to construct a reconstruction.

Origin pixel value is: (43,202)

Therefore the formula I used was: (x values - 43) and (202 - y values).

The reconstructed graph had a good fit from the original handsketched graph: (The fit can be compared with one another, using MS Excel, by filling the chart area with the scanned handsketched graph.)


I give myself 10/10 neutrinos because of the good correspondence between the handsketched graph and the reconstructed one.

posted by poy @ 2:13 AM   1 comments
 
About Me

Name: poy
Home: Quezon City, NCR, Philippines
About Me:
See my complete profile
Previous Post
Archives
Template by
Blogger templates