
We've been having difficulties with siptoolbox here at the CSRC--meaning this activity is post-poned until prior notice.
For now, we've been instructed to generate an image for Activity 2. I came up with this one:

The geometric shape in the binary image needs to be of known area, thus I generated a 320px x 320px image. I cut it diagonally in half, and flipped the inner triangle to obtain the image. Since the image can be reduced to a triangle of half the area of a 320px x 320px square, the area is simply:
320*320 = 102400*0.5 = 51200 square pixels
Apparently, we needed two more images, and here they are:


I set my convention to obtaining the area of the black-shaded regions. The are of the image at the left is simply the area of a triangle of length and base equal to 160px:


I set my convention to obtaining the area of the black-shaded regions. The are of the image at the left is simply the area of a triangle of length and base equal to 160px:
0.5*160 px*160 px = 12800 square pixels
Thus, the area of the image at the right is simply equal to half the area of the image subtracted by the area of the inner triangle:
51200 square pixels - 12800 square pixels
= 38400 square pixels
= 38400 square pixels
In order to compute for the experimental values, I used the function follow() found on the SIP toolbox. The important chunk of code to use would be:
and in order to compute the area, we use Green's Theorem:
n=length(x);
A=0;
for i=1:n-1;
Ai=0.5*(x(i)*y(i+1)-x(i+1)*y(i));
A=A+Ai;
end;
I have Neil to thank for checking my codes. In any case, here are the results:


I used this routine for plotting the follow contours:
xset('window',1)
xbasc()
plot2d(x,y,rect=[0,0,320,320]);
It is important to note that contour assumes the object to be white and its background black. Also, the routine cannot detect any shapes inside a contour, thus making it effective only for contours with defined edges. The area calculated via Green's Theorem yielded the following results:
Image A (unaltered) = 63521 [theoretical: 51200, error: 24.1%]
Image A (sum of B and C) = 50602 [theoretical: 51200, error: 1.17%]
Image A (difference of B and C) = 50840.5 [theoretical: 51200, error: 0.702%]
Image B = 12680.5 [theoretical: 12800, error: 0.934%]
Image C = 37921.5 [theoretical: 38400, error: 1.25%]
I get a 10 for making sure that follow() follows the contour I wanted. xD
image = gray_imread('activity_2c.bmp');
for i=1:320, j=1:320; image(i,j)=(image(i,j)*-1)+1; end;
[x,y]=follow(image);
for i=1:320, j=1:320; image(i,j)=(image(i,j)*-1)+1; end;
[x,y]=follow(image);
and in order to compute the area, we use Green's Theorem:
n=length(x);
A=0;
for i=1:n-1;
Ai=0.5*(x(i)*y(i+1)-x(i+1)*y(i));
A=A+Ai;
end;
I have Neil to thank for checking my codes. In any case, here are the results:



I used this routine for plotting the follow contours:
xset('window',1)
xbasc()
plot2d(x,y,rect=[0,0,320,320]);
It is important to note that contour assumes the object to be white and its background black. Also, the routine cannot detect any shapes inside a contour, thus making it effective only for contours with defined edges. The area calculated via Green's Theorem yielded the following results:
Image A (unaltered) = 63521 [theoretical: 51200, error: 24.1%]
Image A (sum of B and C) = 50602 [theoretical: 51200, error: 1.17%]
Image A (difference of B and C) = 50840.5 [theoretical: 51200, error: 0.702%]
Image B = 12680.5 [theoretical: 12800, error: 0.934%]
Image C = 37921.5 [theoretical: 38400, error: 1.25%]
I get a 10 for making sure that follow() follows the contour I wanted. xD
No comments:
Post a Comment