This site is devoted to mathematics and its applications. Created and run by Peter Saveliev.

# Measuring objects

In this article we discuss various ways to measure objects in the image. Most of them are implemented in Pixcavator.

## Contents

# Binary images

## Area/size

The the most important characteristic of an object is its area, which is simply the number of pixels. It's also the first measurement of importance of the object.

Whatever the "real" (or physical) object is, its area computed this way will be as close as we like to its "true" area as the resolution increases. This is justified by appealing to Lebesgue integral [1]. See also the pictures on the right.

Keep in mind that the area includes the holes in the sense that the area of the holes is not subtracted. This way a thin curve that encloses a region is as large (important) as the region itself.

This approach remains a bit controversial. Maybe holes should be subtracted. You can argue either way. At some point it was decided to go with what was feasible computationally. So far I haven't seen anything that would question this decision.

For more see Area.

## Location of the centroid

The centroid is the center of mass of an object is computed as if this is a lamina with uniform density. Generally, the center of mass is found via computing 3 integrals over the region: the area M and the (first) Moments Mx and My [2]. Then the center of mass has coordinates (My/M,Mx/M). Of course, all symmetric figures - squares, rectangles, parallelograms, circles, ellipses etc - have centers of mass in the center.

An object in a digital image is a collection of pixels. Then the coordinates of the center of mass is the average of all coordinates of the pixels.

Keep in mind that the way we define objects in images, the holes aren't subtracted!

## Perimeter

The perimeter of an object is the number of edges around the object.

The perimeter is easy to compute but the result depends on the orientation of the object with respect to the grid. Therefore it is not a good way to measure objects in digital images.

For more see Perimeter. The more general issue of measuring lengths of curves is addressed in Lengths of curves.

## Roundness

Roundness is defined as follows.

Roundness = 4π*area/perimeter^2

Then roundness of circle = 1, roundness of a square = .8, elongated objects will have lower roundness.

For more, see Roundness.

# Gray scale images

Start with Objects in gray scale images.

An object in a gray scale image is still a collection of pixels, just like in the binary image. If one ignores the gray values of these pixels, the main measurements of the object are the same: Area/size, location of the center of mass, and perimeter. They are computed in the exactly the same way.

We will use the image below as an example. The complete data set of this image - areas, intensities, contrasts, etc - is provided [3].

## Intensity

The gray level within the object runs between 0 and 255.

The intensity of a dark object is the lowest level of gray within it. The intensity of a light object is the highest level of gray within it.

For example, rectangle #1 has intensity 0 (black). The intensity of rectangle #5 is 255 (white). Using the average gray level, *average intensity*, also makes sense. And so does average color. For more see Intensity.

## Contrast

The contrast of an object measures how different it is from its background [4]. Simply put it's max gray level - min gray level of the object. More precise definition is below.

Contrast of a dark object = highest gray level adjacent to it - lowest gray level within it = highest gray level adjacent to it - object's intensity Contrast of a light object = highest gray level within it - lowest gray level adjacent to it = object's intensity - lowest gray level adjacent to it

For example, the intensity of object #12 is 192 and that of #11 is 128. Therefore, the contrast of object #12 = 192 - 128 = 64. Using the average intensity within the object instead of max/min, Average contrast, also makes sense.

For more see Contrast.

## “Saliency”

The area/size of an object can be understood as its mass as if this is a lamina with uniform density. However, this approach ignores the gray values of the pixels.

In case of a gray scale image we have an alternative. We can treat the gray values as values of the density of the lamina.

The total amount of gray, or **mass** (that may be a better name for this), in the object in comparison to the the surrounding area is the most complete characteristic of its importance.

Saliency of a dark object = the sum of (the gray value of the surrounding area - the gray value of the pixel), over all pixels in it Saliency of a light object = the sum of (the gray value of the pixel - the gray value of the surrounding area), over all pixels in it

For example, object #11 has 280 pixels of gray level 0 (from the black rectangle #13), 567 pixels of gray level of 128 (from rectangle #12), and 4984 - 280 - 567 = 4137 pixels of gray level 192 (the rest). Since it is surrounded by white (255), its saliency is

280*(255-0) + 567*(255-128) + 4137*(255-192) = 404,040

Even though this may be the best way to approach the size and importance of objects, the algorithm is implemented in such a way that holes aren't subtracted. Just like with the area the result is that a thin curve that encloses a region is as large (important) as the region itself. Once again you can argue either way but the current approach is more feasible computationally.

For more see Saliency.

## Center of mass

The center of mass of an object can be understood as if this is a lamina with uniform density. In other words, we ignore the gray values of the pixels.

In case of gray level image we have an alternative. We can treat the gray values as values of the density of the lamina.

Then, the center of mass is found via computing the area M and the (first) Moments Mx and My. Then the center of mass has coordinates (My/M,Mx/M).

An object in a digital image is a collection of pixels. Then the coordinates of the center of mass is the weighted average of all coordinates of the pixels. The weights are of course the gray values of these pixels.

Keep in mind that the way we define objects in images, the holes aren't subtracted!

## Average contrast

The contrast of an object is the maximal difference of its gray level from its background. Roughly, it's max gray level - min gray level of the object. Alternatively one can consider the average instead of max/min. More precise definition is below.

Average contrast of a dark object = the gray value of the surrounding area - average gray level within it = the gray value of the surrounding area - object's average intensity Average contrast of a light object = average gray level within it - the gray value of the surrounding area = object's average intensity - the gray value of the surrounding area

The average contrast can be computed as saliency / area.

# Objects as mountaintops

To provide yet another illustration of the meaning of these characteristics of objects let's consider this analogy.

The gray scale function of an image is a function of two variables. It is represented by its graph which is a surface. The objects correspond to maxima (light) and minima (dark) of this function and their combinations.

So, we can think of *light objects* as mountaintops. More precisely, they are what is removed when the mountaintop is removed (that actually happens around here - coal mining etc [5]).

Now, one can measure these mountaintops and the amount of work done in a number of ways.

One can measure the size of the flat area left after the removal. That's the **size** or area of the object.

One can measure the depth of the ground that has been removed, or by how much the mountain has become shorter. That's the **contrast** of the object.

One can measure the amount (volume, mass) of ground that has been removed. That's the **saliency**.

*Dark objects* are valleys...

See also Computation error.

For real life examples see Measuring and browse our numerous image analysis examples.

Most of these measurements are shown in the Pixcavator's output table. To experiment with the concepts, download the free Pixcavator Student Edition.