Thursday, June 19, 2008

Area Estimation for Images

In this activity, we tried to measure the size, in pixel count, of some regular shapes.
We used the SIP toolbox in scilab to load the images then we used Green's theorem to approximate pixel area of the drawn shapes. The SIP command "follow" was used to obtain the contour that was used in Green's theorem. To see if the approximations were accurate, I used a simple pixel count of the image. (1 corresponds to white and 0 to black, so the sum corresponds to the pixel area).
The obtained area using Green's theorem and pixel counts were:
100x100 square:
greens = 9801.
pixelcount = 10000.

50 pixel radius triangle:
greens = 7567.
pixelcount = 7708.

100x100(base x height) triangle:
greens = 4704.5
pixelcount = 4851.

100x150 rectangle:
greens = 14751.
pixelcount = 15000.

The obtained results were quite accurate.
For this activity, I give myself a grade of 9 since I think I performed the activity quite well. Raf also helped me with some scilab codes.

Scilab code used:
im1 = imread("100x150rect.bmp");
im1 = im2bw(im1, 1);
[x, y] = follow(im1);
sx = size(x);
sy = size(y);
sx = sx(1);
sy = sy(1);
x1 = x;
y1 = y;

x1(1) = x(sx);
x1(2:sx) = x(1:(sx-1));
y1(1) = y(sy);
y1(2:sy) = y(1:(sy-1));

xy1 = x.*y1;
yx1 = y.*x1;

greens = abs(0.5*sum(xy1-yx1))

pixelcount = sum(im1)

1 comment:

Jing said...

Hi Ed,

A 10 is in order if you can explain the reason for the disparity in values.