Skogen
Skogen

Reputation: 721

How can I calculate the area of an object by using its contour (chain code)?

Say I have a rotated squared object with chain code [1, 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7] using 8-connectedness. How can I derive its area, as in number of pixels?

EDIT:

I derived the chain code from the boundary pixels. If it is easier to calculate the area by the boundary pixels, how can this be done?

The algorithm should be able to find the number of pixels enclosed by the boundary (including the boundary pixels). The shape of the boundary can be arbitrary, as long as it is closed and does not intersect with itself.

Upvotes: 3

Views: 2435

Answers (3)

Peter Webb
Peter Webb

Reputation: 681

See Wikipedia: Pick's Theorem.

This is an extraordinary result, which applies only if the vertices have integral co-ordinates in some representation of the plane. I think this is true in your case. If it is, it provides a very simple way of calculating the area.

Upvotes: 0

Niki
Niki

Reputation: 15867

The area of any polygon can be calculated from its vertices using this formula:

A = 1/2 Sum(i = 1..n, x[i]*y[i+1] - x[i+1]*y[i])

Source: Wolfram MathWorld

Upvotes: 2

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23727

formula
where
n - number of border pixels,
(x_k, y_k) - coordinates of k-th border pixel (derived from your chain code by assuming x_1=0, y_1=0),
(n+1)-th pixel is the first pixel.

Upvotes: 1

Related Questions