The goal of this activity is to get the area of a regular geometric image (i.e. circle, rectangle, triangle). To do this, we use the 'follow' command in SIP toolbox of SciLab to obtain the edge pixel values of an image and then use these values (these values form the contour of the shape) to obtain the area bounded by this contour using Green's theorem.
The following illustrates the code which I used in implementing Green's theorem for computing areas bounded by a contour.
---
//Area Estimation for Images with Defined Edges
//Julie Mae B. Dado
//AP186
TestImg=imread('C:\Documents and Settings\AP186user03\Desktop\rect.jpg');
TestImg=im2bw(TestImg,0.5);
//imshow(TestImg);
[x,y]=follow(TestImg);
size_x=length(x);
size_y=length(y);
x1(1)=x(size_x);
x1(2:size_x)=x(1:size_x-1);
y1(1)=y(size_y);
y1(2:size_y)=y(1:size_y-1);
area=0.5*sum((x1.*y)-(y1.*x));
//theoretical area
tarea=(max(x)-min(x))*(max(y)-min(y)); //rectangle or square
//tarea=%pi*(((max(x)-min(x))/2)^2); // circle
//tarea=0.5*(max(x)-min(x))*(max(y)-min(y)); //triangle
---
RESULTS:
*Image size: 63x71
Test Image 1: Rectangle
//Area Estimation for Images with Defined Edges
//Julie Mae B. Dado
//AP186
TestImg=imread('C:\Documents and Settings\AP186user03\Desktop\rect.jpg');
TestImg=im2bw(TestImg,0.5);
//imshow(TestImg);
[x,y]=follow(TestImg);
size_x=length(x);
size_y=length(y);
x1(1)=x(size_x);
x1(2:size_x)=x(1:size_x-1);
y1(1)=y(size_y);
y1(2:size_y)=y(1:size_y-1);
area=0.5*sum((x1.*y)-(y1.*x));
//theoretical area
tarea=(max(x)-min(x))*(max(y)-min(y)); //rectangle or square
//tarea=%pi*(((max(x)-min(x))/2)^2); // circle
//tarea=0.5*(max(x)-min(x))*(max(y)-min(y)); //triangle
---
RESULTS:
*Image size: 63x71
Test Image 1: Rectangle
Area Computed Using Green's Theorem: 1763
Theoretical Area (pixel count): 1763
% Error: 0%
Test Image 2: Triangle
Area Computed Using Green's Theorem: 876.5
Theoretical Area (pixel count): 860
% Error: 1.9%
Test Image 3: Circle (large)
Area Computed Using Green's Theorem: 1658
Theoretical Area (pixel count): 1661.9
% Error: 0.23%
Test Image 4: Circle (medium)
Area Computed Using Green's Theorem: 341
Theoretical Area (pixel count): 346.4
% Error: 1.6%
Test Image 5: Circle (small)
Area Computed Using Green's Theorem: 64
Theoretical Area (pixel count): 78.5
% Error: 18.5%
Observations:
1. Maximum differences between area estimation using Green's theorem (that is, obtaining pixel values for the contour) and analytical estimation of area using pixel counting were observed for circular shapes while minimum errors were observed for rectangular shapes. This error can be accounted for the pixel shape which are actually small squares. Circular shapes relatively do not have smooth contours. (this may be observed if you zoom in on a circular image)
2. For circle with smaller radii, the errors are larger. This is because the smaller the radius, the less number of pixels used to estimate the smooth shape of the circle.
3. Area estimation by obtaining pixel values of a contour used for Green's theorem are somehow limited shapes with straight sides. This technique somehow isn't suited for smooth contours unless pixel values are compensated such that it can approximate the shape with less error.
---
Thanks to...
Jeric for helping me debug my program whenever it doesn't work and for showing me how to obtain theoretical area using pixel counting.
---
Grade: 7/10
because I had a hard time debugging simple errors and that I pretty much didn't analyze how to obtain area using pixel counting.
1 comment:
Your work is the first i've seen that went beyond the requirements - you investigated the effect of the circle diameter to the
accuracy. For this you deserve a 10.
Post a Comment