The LABEL_REGION function consecutively labels all of the regions, or blobs, of a bi-level image with a unique region index. This process is sometimes called “blob coloring”. A region is a set of non-zero pixels within a neighborhood around the pixel under examination.
The argument for LABEL_REGION is an n-dimensional bi-level integer type array—only zero and non-zero values are considered.
Statistics on each of the regions may be easily calculated using the HISTOGRAM function as shown in the examples below.
Examples
Example 1
This example counts the number of distinct regions within an image, and their population. Note that region 0 is the set of zero pixels that are not within a region:
image = DIST(40)
; Get blob indices:
b = LABEL_REGION(image)
; Get population of each blob:
h = HISTOGRAM(b)
FOR i=0, N_ELEMENTS(h)-1 DO PRINT, 'Region ',i, $
', Population = ', h[i]
Example 2
This example also prints the average value and standard deviation of each region:
PRO label_region_ex_2
image = DIST(40)
; Get blob indices:
b = LABEL_REGION(image)
; Get population and members of each blob:
h = HISTOGRAM(b, REVERSE_INDICES=r)
; Each region
FOR i=0, N_ELEMENTS(h)-1 DO BEGIN
;Find subscripts of members of region i.
p = r[r[i]:r[i+1]-1]
; Pixels of region i
q = image[p]
PRINT, 'Region ', i, $
', Population = ', h[i], $
', Standard Deviation = ', STDEV(q, mean), $
', Mean = ', mean
ENDFOR
END
label_region_ex_2
Syntax
Result = LABEL_REGION( Data [, /ALL_NEIGHBORS] [, /ULONG] )
Return Value
The result of the function is an integer array of the same dimensions with each pixel containing its region index. A region index of zero indicates that the original pixel was zero and belongs to no region. Output values range from 0 to the number of regions.
Arguments
Data
A n-dimensional image to be labeled. Data is converted to integer type if necessary. Pixels at the edges of Data are considered to be zero.
Keywords
ALL_NEIGHBORS
Set this keyword to indicate that all adjacent neighbors to a given pixel should be searched. (This is sometimes called 8-neighbor searching when the image is 2-dimensional). The default is to search only the neighbors that are exactly one unit in distance from the current pixel (sometimes called 4-neighbor searching when the image is 2-dimensional).
ULONG
Set this keyword to specify that the output array should be an unsigned long integer.
Version History
| Pre 4.0 |
Introduced |
| Pre 6.1 |
Deprecated the EIGHT keyword |
See Also
Comments
This page has no comments yet. Be the first one!
