Figure 1: Area sets the intensity of quantized regions according to their sizes.
This command determines the area of of contiguous, or 'connected' regions. (See -label for a discussion on connectivity). For each pixel in an image, the command associates it with a particular region and labels it with that region's area. All pixels in a particular region then have identical labels: the count of the region's pixels. Pixels in small areas have low values and are visually dark; those in large areas have high values and are visually light. This distribution of values endows G'MIC image metrics with additional meanings:
The format of the command is:
tolerance>=0,is_high_connectivity={ 0 | 1 }
Pixels endowed with common properties establish regions, pixel color an oft-used property for this purpose.
Figure 2.
The image in Figure 2 has two colors: black and white. We can intuit that there seems to be one black region and perhaps three white regions, Maybe a total of four.
This total is doubtful because two regions just touching at a corner may be construed as both separate or combined. If we qualify low connectivity, then regions touching at corners are considered disconnected. Otherwise, for high connectivity, they are connected.
Two pixels sharing common properties, 'like pixels', are deemed 'connected' if and only if at least one path can run from one to the other without traversing unlike pixels. Regions consist of mutually connected pixels. Put informally, the command attempts a flood-fill and sees how far the flood goes. A flood-fill tests connectivity at each pixel it attempts to engulf with the nearest pixel already engulfed.
There is still an ambiguity. What of the (one? two?) regions just touching at a corner? Resolving that ambiguity is what the connectivity flag argument to the -area command is for. When it is set to zero, low connectivity, two regions just touching at corners, are deemed unconnected; you are not allowed to run a path through that narrow defile. Set it to one, high connectivity, and you are; the two erstwhile regions are considered as one.
In many images, what might be considered a region have fuzzy borders, which is when tolerance comes into play. When it is zero, two pixels must have exactly the same value in order for them to be contiguous. Positive values permit unequal pixels to be considered equivalent, so long as their intensity differences are less than the tolerance.
With an unambiguous means to establish regions, -area tabulates areas and reports these using gray scales; the intensity value of all pixels in a particular region are set to the pixel count (in effect, 'area') of that region.
Areas of three regions. High Connectivity evaluation | Areas of four regions. Low connectivity evaluation |
Garry Osgood