BLOBCOUNT Function
Standard Library function that identifies homogeneous regions in an array.
Usage
result = BLOBCOUNT(a, b)
Input Parameters
a—An n-dimensional array.
b—A two-element vector of bounds for values in a region.
Returned Value
result—A list in which each element defines one of the distinct regions whose values lie in the range [b(0), b(1)]. result(j) is a (m(j), n) array of m(j) n-dimensional indices into a. If no such regions exist, then result is returned as –1.
Keywords
K—A positive integer (less than or equal to n) controlling connectivity: Two cells are connected if they share a common boundary point, and if their centroids are within the square root of K of each other. K = 1 by default, which implies that connected cells share a common face.
In1d—If In1d is set then the result is in 1-dimensional instead of n-dimensional indices.
Discussion
BLOBCOUNT generalizes region-growing image segmentation to ND arrays. Given an ND array and a real closed interval I, BLOBCOUNT finds all connected regions with values in I. Connectivity is defined by representing the array as a collection of unit N-cubes, where by default, connected array cells share a common face: that is, their centroids are unit distance apart. Larger values of keyword K relax this definition of connectivity. In a 3D array for example, K = 2 admits both face-wise and edge-wise connectivity, and K = 3 admits face-wise, edge-wise, and corner-wise connectivity. For maximum efficiency, use keyword In1d so that result is represented in 1D indices instead of ND indices.
Example 1
; Read a 24-bit image
img = IMAGE_READ(!Data_dir + 'rw_logo.jpg')
; Get the pixels array
pix = img('pixels')
; Open plotting window 0
WINDOW, 0, Xsize=202, Ysize=159, Xpos=100, Ypos=650
; Display the image
TV, pix, 1, True=3
; Represent image in 2-d
pix2d = pix(*,*,0) + 256L*pix(*,*,1) + 256L^2*pix(*,*,2)
; Open plotting window 1
WINDOW, 1, Xsize=500, Ysize=400, Xpos=100, Ypos=200
; Find 'black' threshold
PLOT_HISTOGRAM, HISTOGRAM(pix2d, BinSize=1000)
; Find 'black' regions
blobs = BLOBCOUNT(pix2d, [0,4e6])
; Number of regions
n = N_ELEMENTS(blobs)
PRINT, 'Number of regions found: ', STRTRIM(n, 2)
; Transpose for plotting
FOR j=0L,n-1 DO blobs(j) = TRANSPOSE(blobs(j))
; Open plotting window 2
WINDOW, 2, Xsize=202, Ysize=159, Xpos=350, Ypos=650
; Display the image again
TV, pix, 0, True=3
; Change black to red
FOR j=0L,n-1 DO PLOTS, blobs(j), /Device, Psym=3, Color=255
Example 2
See wave/lib/user/examples/blobcount_ex.pro
This 2D example is similar to the previous one, but here the user can choose the input image and the connectivity parameter. In this demo however, the regions are not shaded with different colors.
See Also