In this activity, what we need to do is to find the area of a
certain region of concern in an image by (1) counting the pixels enclosed by
the said region and (2) by using Green's theorem whose discrete form is
given by:
In pixel counting, we need our image to be binarized such that the
area of interest is white and the background is black. Then to find the area,
we just count the number of pixels which are white (or 1).
2. Green's Theorem
To able to use Green's theorem we first need to learn how to take
the points which consist the contour of the said region. This is fairly easy to
do if your image has defined bounds by using the edge() command in SciLab and
finding the indices of the array elements which are white. But another
requirement of Green's theorem is for the contour to be taken either in the
clockwise or counterclockwise direction. This is where the challenge
lies. One technique in sorting the points is by taking
the angles between the x-axis and the line which connects the points to the
center of the image which acts as the origin.
3. Code Snippet
The code snippet below shows the implementation of the technique in SciLab.
The code snippet below shows the implementation of the technique in SciLab.
//Load image as array
I =
imread("C:\Users\Tin\Desktop\AP_186\Act4-Area Estimation\square_250.bmp");
//Actual areas
area1 = 250*250
area2 = %pi*125^2
//Estimate area by pixelcount
pixels = size(find(I > 0));
pixelcount = pixels(2);
err_p = (pixelcount - area1)/area1;
//For Green's theorem
//Isolate edge
E = edge(I, 'canny',0)
E = bool2s(E);
//find points on edge
[i,j]= find(E);
ind = [i;j]';
//plot(ind(:,1),ind(:,2),"bo")
s = size(I); // size of image
n = size(ind); // size of index list
//set origin at center of image
c_x = s(1)/2;
c_y = s(2)/2;
//Calculate angles
t = n(1);//for limit of for loop
angles = zeros(n(1));
for i =1:t
x = -(ind(i,1)-c_x);
y = ind(i,2)-c_y;
r = (x^2 + y^2)^0.5
if x==0 & y>=0 then
angles(i) = 90;
elseif x==0 & y<0 then
angles(i) = 270;
elseif x<0 & y<=0 then
angles(i) =
atan(y/x)*180/%pi + 180;
elseif x>0 & y<=0 then
angles(i) = 360 +
atan(y/x)*180/%pi;
elseif x>0 & y>0 then
angles(i) =
atan(y/x)*180/%pi;
elseif x<0 & y>0 then
angles(i) =
atan(y/x)*180/%pi + 180;
end
end
//save angles (x,y) pairs in another array then
sort
B = zeros(n(1),3);
B(:,2:3) = ind;
B(:,1) = angles;
C = lex_sort(B);
//Estimate area using Green's theorem
sum_ = 0
for j = 1:t-1
sum_ = sum_ + (C(j,3)*C(j+1,2)-
C(j,2)*C(j+1,3));
end
A = 0.5*sum_;
err_g = (A-area1)/area1;
4. Results for black and white regular geometric
shapes
I used both techniques for different black and white images with
known area. Note that we consider that the actual areas of the regions we are interested in are exactly the same as the regions in white. That is, we consider the edges to be completely smooth instead of being discretized. This way, we will be able to include the errors that may result when we delineate our regions of interest in a real-world scene. The results are as follows (in square pixels):
Actual Area: 62500
Green's theorem: 62559.5 (0.095% error)
Pixel counting: 62500 (0% error)
Actual Area: 10000
Green's theorem: 10079 (0.97% error)
Pixel counting: 10 000 ( 0% error)
Pixel counting: 10 000 ( 0% error)
Actual Area: 49087.4
Green's theorem: 48995.5 (0.19% error)
Actual Area:7854
Green's theorem: 7917 (0.8% error)
Pixel counting: 7820 (0.4% error)
Actual Area: 52932
Green's theorem: 53049 (0.22% error)
Pixel counting: 53167 (0.44% error)
From the estimates obtained using Green's method and pixel counting, the techniques may be considered accurate, yielding percent errors which are less than 1%. Let us now apply the technique to a real-world object or region.
5. real-world application
The following figure shows the City Commercial Center (C3) in our city (Pagadian City) in map view and in its binarized form made using Gimpv.2.8.
Using the code above, the following edge was detected.
The contour is obtained using the code above is shown below:
By counting the number of pixels which correspond to 20m in the scale bar, I obtained a scaling factor of 3.4 pixels/m which I can use to convert my computed area in sq. meters.
Green's theorem: 5849 sq. m.
Pixel counting: 5847 sq. m
These values for the area are good estimates with percent errors less than 2%.
I would like to thank Ms. Maria Isabel Saludares for giving me an idea on the use of angles when my first idea did not work. Also, I thank Mr. Gino Borja and Ms. Eloisa Ventura for helpful discussions on the commands and syntax in SciLab.
Finally, I give my self a grade of 10/10 for being able to take the estimates of areas using Green's theorem and pixel counting. I have gained much skill while doing this activity.
Reference:
M. Soriano, AP 186 Activity 4 - Area estimation for images with defined edges instruction sheet, 2012
From the estimates obtained using Green's method and pixel counting, the techniques may be considered accurate, yielding percent errors which are less than 1%. Let us now apply the technique to a real-world object or region.
5. real-world application
The following figure shows the City Commercial Center (C3) in our city (Pagadian City) in map view and in its binarized form made using Gimpv.2.8.
Using the code above, the following edge was detected.
The contour is obtained using the code above is shown below:
The theoretical area of the region in sq. pixels was determined by manually measuring each side and taking areas of the rectangles that make up the entire region. The areas calculated in square pixels are as follows :
Theoretical: 66830 sq. pixels
Green's theorem : 67622 sq. pixels (1.14% error)
Pixel counting: 67595 sq. pixels (1.18% error)
Green's theorem: 5849 sq. m.
Pixel counting: 5847 sq. m
These values for the area are good estimates with percent errors less than 2%.
I would like to thank Ms. Maria Isabel Saludares for giving me an idea on the use of angles when my first idea did not work. Also, I thank Mr. Gino Borja and Ms. Eloisa Ventura for helpful discussions on the commands and syntax in SciLab.
Finally, I give my self a grade of 10/10 for being able to take the estimates of areas using Green's theorem and pixel counting. I have gained much skill while doing this activity.
Reference:
M. Soriano, AP 186 Activity 4 - Area estimation for images with defined edges instruction sheet, 2012
Comments
Post a Comment