connected(X, background = NA, method="C")
"im"
) or window (object of class
"owin"
)."C"
or "interpreted"
. See Details."im"
) with factor values.
The levels of the factor correspond to the connected components.method="interpreted"
can be very slow for large images (or images where
the connected components include a large number of pixels).X
is first
converted into a pixel image with logical values. Then the algorithm
identifies the connected components (topologically-connected clumps
of pixels) in the foreground. Two pixels belong to the same connected component if they have the value
TRUE
and if they are neighbours (in the 8-connected
sense). This rule is applied repeatedly until it terminates.
Then each connected component
contains all the pixels that can be reached by stepping from neighbour
to neighbour.
If method="C"
, the computation is performed by a compiled C language
implementation of the classical algorithm of Rosenfeld and Pfalz
(1966). If method="interpreted"
, the computation is performed
by an Rimplementation of the algorithm of Park et al (2000).
The result is a factor-valued image, with levels that correspond to the connected components. The Examples show how to extract each connected component as a separate window object.
Rosenfeld, A. and Pfalz, J.L. (1966) Sequential operations in digital processing. Journal of the Association for Computing Machinery 13 471-494.
im.object
,
tess
data(cells)
d <- distmap(cells, dimyx=256)
X <- levelset(d, 0.06)
plot(X)
Z <- connected(X)
plot(Z)
# number of components
nc <- length(levels(Z))
# plot with randomised colour map
plot(Z, col=hsv(h=sample(seq(0,1,length=nc), nc)))
# how to extract the components as a list of windows
W <- tiles(tess(image=Z))
Run the code above in your browser using DataLab