Wednesday, June 18, 2008
activity 2: area estimation for images with defined edges
The figures I used is a square with a pixel area of 96x97, a 155x84 pixels rectangle and a circle with radius of 48 pixels which I counted manually by locating the edges' pixel coordinates. Using functions in the siptoolbox, the image was converted easily into a binary array. Then manipulating this values, we can locate the edge coordinates of the image (or its contour coordinates) using the function 'follow'. A matrix shifted forward by one element has to be created as a requirement in the Green's Theorem equation. Using Green's Theorem, the area of the image was easily computed.
Results: The theoretical area of the figures I used are 9312 pixels, 13020 pixels and 7238.22 pixels for square, rectangle and circle respectively. Their corresponding areas calculated via green's Theorem are 9216 pixels,13104 pixels and 7208 pixels respectively. Their corresponding discrepancies are 1.03%, 0.65% and 0.42% respectively. In that case, I can asses that I managed to compute for the images areas to a good degree of accuracy. Discrepancies arise due to difference in pixel locations of the binary image and the actual image. There is a small shift in the coordinates that will affect the contour coordinates.
Rating: I would like to acknowledge my collaborator Mr. Carl Nicollo Fabros for helping me to use what functions needed. This tme I will give myself a grade of 10.0 because based from the results I got, I am confident that I did a good job.
The Code:
Square:
/to load the image into binary array
I=imread('C:\Documents and Settings\AP186user02\Desktop\square2.jpeg');
//to get the coordinates of the contour
[x,y]=follow(I);
//to shift the x and y array
lx=length(x);
ly=length(y);
x1(1)=x(lx);
x1(2:lx)=x(1:lx-1);
y1(1)=y(ly);
y1(2:ly)=y(1:ly-1);
//actual pixels counted
t_area=97*96
//to compute for the area and %error using Green theorem
area=abs(0.5*sum(x1.*y-x.*y1))
da=100*(t_area-area)/t_area
Rectangle
//to load the image into binary array
I_rect=imread('C:\Documents and Settings\AP186user02\Desktop\rect.jpeg');
//to get the coordinates of the contour
[x,y]=follow(I_rect);
//to shift the x and y array
lx=length(x);
ly=length(y);
x1(1)=x(lx);
x1(2:lx)=x(1:lx-1);
y1(1)=y(ly);
y1(2:ly)=y(1:ly-1);
//actual pixels counted
t_area=155*84
//to compute for the area and %error using Green theorem
area=abs(0.5*sum(x1.*y-x.*y1))
da=100*(t_area-area)/t_area
Circle
//to load the image into binary array
I_circle=imread('C:\Documents and Settings\AP186user02\Desktop\circle.jpeg');
//to get the coordinates of the contour
[x,y]=follow(I_circle);
//to shift the x and y array
lx=length(x);
ly=length(y);
x1(1)=x(lx);
x1(2:lx)=x(1:lx-1);
y1(1)=y(ly);
y1(2:ly)=y(1:ly-1);
//actual pixels counted
r=48
t_area=%pi*r*r
//to compute for the area and %error using Green theorem
area=abs(0.5*sum(x1.*y-x.*y1))
da=100*(t_area-area)/t_area
----End of Blog------
Subscribe to:
Post Comments (Atom)
1 comment:
Yep, that looks like a well-deserved 10 there.
Post a Comment