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:
Post a Comment
<< Home
 
 
About Me

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