11
COMPUTER VISION, GRAPHICS, AND IMAGE PROCESSING u, 207-2 17 (1983) NOTE A New Three-Dimensional Connected Components Algorithm RONALD LUMIA Department of Electrical Engineering, Virginia Polytechnic Institute and State University, Blackrburg, Virginia 24061 Received May 21, 1982; revised June 14, 1982 An efficient new algorithm which calculates the connected components of a binary image has recently been reported. The algorithm has been extended to a three-dimensional image. With a relatively small equivalence table, this algorithm is suitable for both large and small computer systems. I. INTRODUCTION The connected components algorithm transforms a binary image B into a symbolic image S such that all pixels in B which are 0 will remain 0 in S and that every maximally connected subset of 1 values in B is labeled by a distinct integer in S. The original algorithm was developed by Rosenfeld and Pfaltz [I]. The idea for the connected components algorithm is to scan each line of the binary image from left to right and to assign labels to the one values. This is illustrated by considering two lines of a binary image: liner-l x x B x x line r xCAxx Supposethe pixel labeled A is a 1. We will assignA a label in the following manner: ifB=C=O Then A is given the next available label. ifB=O CzO Then A is given C’s label. ifB*O C=O Then A is given B’s label. ifBe C*O Then A is given the smaller of the two labels and the equivalence of B’s label and C’s label must be stored. The way in which label equivalences are handled can have a dramatic effect upon the amount of computer processing time. Lumia et al. [2] have developed a new connected components algorithm which significantly reduces the required processing time. In their method, the label equivalencetable is only the length of one line of the image. In a virtual memory computer, such as the VAX 1 l/780, the required processing time was 36 times faster than the standard approach for a large image. 207 0734-189X/83 $3.00 Copyright 0 1983 by Academic Press. Inc. All rights of reproduction in any form reserved.

A new three-dimensional connected components algorithm

Embed Size (px)

Citation preview

Page 1: A new three-dimensional connected components algorithm

COMPUTER VISION, GRAPHICS, AND IMAGE PROCESSING u, 207-2 17 (1983)

NOTE

A New Three-Dimensional Connected Components Algorithm

RONALD LUMIA

Department of Electrical Engineering, Virginia Polytechnic Institute and State University, Blackrburg, Virginia 24061

Received May 21, 1982; revised June 14, 1982

An efficient new algorithm which calculates the connected components of a binary image has recently been reported. The algorithm has been extended to a three-dimensional image. W ith a relatively small equivalence table, this algorithm is suitable for both large and small computer systems.

I. INTRODUCTION

The connected components algorithm transforms a binary image B into a symbolic image S such that all pixels in B which are 0 will remain 0 in S and that every maximally connected subset of 1 values in B is labeled by a distinct integer in S. The original algorithm was developed by Rosenfeld and Pfaltz [I].

The idea for the connected components algorithm is to scan each line of the binary image from left to right and to assign labels to the one values. This is illustrated by considering two lines of a binary image:

liner-l x x B x x line r xCAxx

Suppose the pixel labeled A is a 1. We will assign A a label in the following manner:

ifB=C=O Then A is given the next available label.

ifB=O CzO Then A is given C’s label.

ifB*O C=O Then A is given B’s label.

ifBe C*O Then A is given the smaller of the two labels and the equivalence of B’s label and C’s label must be stored.

The way in which label equivalences are handled can have a dramatic effect upon the amount of computer processing time. Lumia et al. [2] have developed a new connected components algorithm which significantly reduces the required processing time. In their method, the label equivalence table is only the length of one line of the image. In a virtual memory computer, such as the VAX 1 l/780, the required processing time was 36 times faster than the standard approach for a large image.

207 0734-189X/83 $3.00

Copyright 0 1983 by Academic Press. Inc. All rights of reproduction in any form reserved.

Page 2: A new three-dimensional connected components algorithm

208 RONALD LUMIA

Park and Rosenfeld [3] have generalized the original connected components algorithm for three-dimensional binary images. The label equivalence problem is managed in precisely the same fashion as that of the two-dimensional algorithm.

In this paper, the new connected components algorithm will be extended to three dimensions. The three-dimensional binary image can be described as a series of two-dimensional images arranged in bands. Pixels can be adjacent to pixels within the band (two dimensions) as well as to certain pixels on either adjacent band (three dimensions). The principle of operation is quite similar to that described in [2] except that now bands replace lines. First the two-dimensional connected compo- nents algorithm is run on each band separately. Then, the pixel adjacencies between bands are determined by processing from band 1 to the last band and back to band 1 with appropriate label propagation. This process is described formally in Section 2. Section 3 illustrates the algorithm and tabulates the processing time for various sized images.

2. DESCRIPTION OF THE ALGORITHM

The three-dimensional connected component algorithm will be described in terms of a precise sequence of operations using the following notation.

NLINES: NPIXELS: L: P: B: I(L, P, B): LABEL (L, P, B): EQTABLE: A:

M: CREATE: ADJACENT: ISEMPTY: NEWLABEL:

ADD: EQUIVCLASS: MINLAB:

LA:

BA:

NBANDS:

number of rows in the image number of columns in the image row index column index band index input value at row L, column P, band B output value (integer label) for row L, column P, band B label equivalence table set of pixels on the current or previous line and adjacent to

pixel (L, P, B) that have value 1 and are already labeled label initially assigned to pixel (L, P, B) a function that returns an empty equivalence table a function that determines if two pixels are adjacent a function that determines if a set is empty a function that returns the next chronological integer label

that has not yet been used a procedure that adds a pair of labels to the equivalence table a function that returns the equivalence class of a given label a function that returns the minimum label in a given equiva-

lence class, which is used to represent that class. the set of nonzero labels on the current or previous line which

are adjacent to pixel (L, P, B) the set of nonzero labels on the current or previous band

which are adjacent to pixel (L, P, B) the number of bands in the three-dimensional image

RLBL (B, START, MAX): routine that relabels the connected components on band B

starting with label START. It returns MAX, the largest label used.

Page 3: A new three-dimensional connected components algorithm

3-D CONNECmD COMPONENT 209

The three-dimensional connected component algorithm performs the following steps:

1. Determine the two-dimensional connected components for each band in the image.

2. Relabel the connected components. Starting with band 1 and finishing with band NBANDS, number all connected components sequentially. After this opera- tion all labels on band r will be greater than any label on bands 1 to r - 1.

3. Process from the first to the last band propagating the label equivalences. This is the same basic process as that of the two-dimensional components algorithm except that the propagation is now between the bands rather than between the rows. Repeat this process going from the last band to the first band.

“A two-dimensional connected components algorithm is first run on each band separately” for B:= 1 to NBANDS do begin

for L: = 1 to NLINES do begin “create empty equivalence table for line L” EQTABLE: = CREATE ( ); “set all labels initially to 0” for P:= 1 to NPIXELS do

LABEL(L, P): = 0; for P: = 1 to NPIXELS do

begin if I(L, P, B) = 0 then NEXT endif; A: = {N, Q, B)](I(L, P, B) = 1) and

LABEL(N, Q) f 0) and (N = LorN = L - 1)and ADJACEN’WN, Q, B), 6, P, B));

if ISEMPTY (A) then M:= NEWLABEL ( ) else M: = min{LABEL(N, Q, B) 1 (N, Q, B) E A) endif LABEL(L, P): = M;

“store new equivalences” for X E {LABEL(N, Q, B) ((N, Q, B) E A} and X G M

call ADD((X, M), EQTABLE) end

“update equivalence classes for line L” for P:= 1 to NPIXELS do

if I(L, P, B) = 1 then LABEL(L, P, B): = MINLAB(EQUIVCLASS(LABEL(L, P)))

endif; end

Page 4: A new three-dimensional connected components algorithm

210 RONALD LUMIA

Pass 2 of two-dimensional connected components for L:= NLINES to 1 by - 1 do

begin “create equivalence table for line L” EQTABLE:= CREATE ( ); for P: = 1 to NPIXELS do

begin if LABEL (L, P, B) = 0 then NEXT endif; LA: = {LABEL(N, Q, B) 1 LABEL(N, Q, B) f 0 and

(N = L or N = L + 1) and ADJACEWW, Q, W, CL, P, W)

“store new equivalences” for X E LA and X 4 LABEL(L, P, B)

cull ADD((X, LABEL(L, P, B)), EQTABLE) end

“ update equivalence classes for line L” for P: 1 lo NPIXELS do

if LABEL(L, P, B) * 0 then LABEL(L, P, B) = MINLAB(EQUIVCLASS(LABEL(L, P, B))) endif;

end

“Relabel all connected components consecutively from band 1 to NBANDS. Then all labels on band r have larger values than any labels on bands 1 through 1.”

STRT:= 1 for B: 1 to NBANDS do begin

cull RLBL(B, STRT, MAX) STRT:=MAX+ 1

end “Three-dimensional connected components” “PASS l-FROM BAND 1 TO THE LAST BAND” “Copy Band 1 to output file” for L: = 1 to NLINES do

begin for P:= 1 to NPIXELS do LABEL(L, P, 1) = I(L, P, 1);

end for B:= 2 to NBANDS do

begin “create empty equivalence class for band B” EQTABLE:= CREATE ( ); for L:= 1 to NLINES do

begin for P: = 1 to NPIXELS do begin if I(L, P, B) = 0 then NEXT endif; “find adjacent labels between bands”

Page 5: A new three-dimensional connected components algorithm

3-D CONNECTED COMPONENT 211

BA: = (LABEL(N, Q, BND)( I(N, Q, BND) f 0 and ADJACENT((N, Q, BND), (L, P, B)) and (BND=BorBND=B- 1))

if ISEMPTY (LA) then NEXT else M: = min{LABEL(N, Q, BND) 1 LABEL(N, Q, BND) E BA} jorXEBAandX*M

call ADD((X, M), EQTABLE) end

end “Update current band’s labels.” for L: = to NLINES do

begin for P: 1 to NPIXELS do

begin if LABEL(L, P, B) = 0 then NEXT endif; LABEL(L, P, B): = MINLAB (EQUIVCLASS(LABEL(L, P, B)))

end end

“Pass 2-From last band to band 1” for B:= NBANDS - 1 to 1 by - 1 do

begin “create empty equivalence table” EQTABLE:= CREATE ( ); for L = 1 to NLINES do

begin if LABEL(L, P, B) = 0 then NEXT endif;

BA: = {LABEL(N, Q, BND) 1 LABEL(N, Q, BND) f 0 and (BND = B or BND = B + 1) and ADJACENT(N, Q, BND), (L, P, B)))

if ISEMPTY (A) then NEXT else M: = min{LABEL(N, Q, BND) 1 LABEL(N, Q, BND E BA} endij; jorX E BAandX f M

calZ ADD((X, M), EQTABLE) end

end “UPDATE BAND LABELS’ for L: = 1 to NLINES do begin

for P:= 1 to NPIXELS do begin

if LABEL(L, P, B) = 0 then NEXT endij; LABEL(L, P, B): = MINLAB(EQUIVCLASS(LABEL(L, P, B)));

end end

Page 6: A new three-dimensional connected components algorithm

212 RONALD LUMIA

3. EXPERIMENTAL RESULTS

The three-dimensional connected components algorithm will be illustrated first in terms of the procedure and then in terms of the processing time.

To illustrate the method, a three-dimensional checkerboard pattern was created. This checkerboard has 25 rows, 25 columns, and 3 bands. Band 1 and band 3 were created with three by three pixel squares while band 2 consists of five by five pixel squares. The three bands of the original image are shown in Figs. la, b, and c.

The first step in the three-dimensional connected components process is to run a two-dimensional connected components algorithm independently on each of the bands of the image. The results are shown in Figs. 2a, b, and c.

Since the connected components for each band begin with the label 1, a three- dimensional relabeling must be done next so that all of the labels are consecutively labeled from the first band to the last. Figures 3a, b, and c illustrate the results of this process.

Now the three-dimensional connection begins. Adjacent labels between bands are detected and relabeled with the smallest equivalent label. As described in Section 2, a pass from band 1 to the last band and back is required. The three-dimensional checkerboard results are shown in Figs. 4a, b, and c. It is interesting to see how some of these connections occurred. Note in the relabeled image bands (Figs. 3a and b) that region 41 (band 2) connects regions 1, 2, and 6 of band 1. Since label 1 is the smallest, each of these regions is given label 1 in the three-dimensional connected components image of Fig. 4. A similar connection between bands is responsible for the propagation of region 23.

The three-dimensional connected component algorithm was tested for two differ- ent sized checkerboard images as a function of the number of bands. The first set of checkerboard images had 100 rows and 100 columns and a variable number of bands (third dimension). The central processor unit (CPU) time required is summarized in Table 1 for an implementation of the algorithm on a VAX 1 l/780. Even though the 32-band image has 320 K pixels, the required processing time is still proportional to the image size. This indicates that the algorithm does not suffer from excessive page faulting as image size increases which was previously shown to be an important factor [2].

Table 2 summarizes a similar experiment for a set of checkerboards with 25 rows and 25 columns. In this case, the processing time appears to be significantly less than linear, i.e., an image which is twice as large requires less than twice the processing time. This can be explained by the fact that the image processing system has a certain amount of computational overhead regardless of the size of the image being processed. For smaller images, this overhead can become a reasonably large per- centage of the total processing time.

4. CONCLUSION

This paper has developed an efficient algorithm for the calculation of the con- nected components of a three-dimensional image. The algorithm requires a reason- able amount of CPU time and does not suffer from excessive page faulting as image size increases. Since the algorithm is implemented in several steps, a large amount of storage is not necessary. Consequently, the algorithm is appropriate for both large computer systems as well as for small facilities.

Page 7: A new three-dimensional connected components algorithm

3-D CONNECTED COMPONENT

0 0 0 0 0 0 0 0 0

: : : 1 1 1 0 0 0 0

O 0 0 ?I : 1

f : :

0 0 :, 0 0 0

i: ‘: O ;

: f 1

0 0 0 0 0 0 0 0 0

: : : 1 1 1 n 0 0

b

FIG. 1. (a) Original image, band I. (b) Original image, band 2. (c) Original image, band 3.

Page 8: A new three-dimensional connected components algorithm

RONALD LUMIA

b

0” : : 4 1 4 G 0 0 : 7 :: 9 ;: c!

0 16 1 0 16 1

2G 0 20 0 20 0

G 25 ;

29 0 29 0

38 0

FIG. 2. (a) Two-dimensional connected components, band I. (b) Two-dimensional connected compo- nents, band 2. (c) Two-dimensional connected components, band 3.

Page 9: A new three-dimensional connected components algorithm

3-D CONNECTED COMPONENT 215

b

FIG. 3. (a) Relabeled three-dimensional image, band I. (b) Relabeled three-dimensional image, band 2. (c) Relabeled three-dimensional image, band 3.

Page 10: A new three-dimensional connected components algorithm

8 BP o~

~~oo

o~~~

oooo

~uoo

oo~~

~*oo

0

729

mm

m

NNN

oBPP

ooow

wwoo

oouu

oooc

nulu

looo

mm

m

NPJN

oP

L*oo

owww

ooou

oooo

oLnu

uooo

NNN

q\1t

i c-

c OW

WW

OOOu

-~u-

OOOU

cn00

00rrr

OOO

NNN

v-J\

1 --+

O

WwW

OO

Ou-

~~O

OO

OUU

000~

rrO

OO

-Lb.

~0

00~~

~000

~U~O

OOVV

~~oo

o~~-

8”

&

PJ

NNN

cc-

8 W

OO

OW

WwO

OO

UUU0

00-J

-J~0

oo~~

+-

89

mm

m

PJNN

G

’F:

oDu-

croo

owww

ooo-

4~~o

oo.J

’<~o

oo

*s

otwo

ook%

~ooo

v+4o

oo+J

-Joo

o

ok%

~ooo

i%!c

ooo~

~.lo

oo~~

~ooo

05

EE

3a

~o

oot%

~ooo

wwwo

oo~L

Looo

www

“W

- 8o

ook%

~ooo

wwwo

oo-tL

Looo

www

~ooo

88~o

ooww

wooo

L~~o

ooww

w

wow

NPJN

N

ONN

NOO

OW

WW

OO

O‘“U

TL”~

~~:~

L~~~

~~~

@

;;;

www

NNN

ONN

NOO

OW

WW

OO

OUO

U~~~

~~~~

~C’

o~~~

ooo~

~~oo

oou~

ooo~

oooo

c~

!l,io

ook%

~ooo

~~~o

oouw

J!oo

o---

~000

~~~0

00~~

5000

U~~~

Ooc~

-~-

cc-

~ooo

KEoo

oouv

ooom

nvoo

o-*-

NNN

FJNN

++

- ow

wwoo

ocPP

ooou

uulo

oo’c’

ooo

NNN

NNN

c-c

OWW

wOOO

PLPO

OO~U

ul00

0---o

oo

NNN

NNN

+--*

OW

WW

OO

OCO

POO

OUu

lU00

0’--o

oc~

~000

~~~0

00~5

~000

~U~o

oo~-

~

N FJ

NN

-+-c

W

OOOW

WW

0000

1ulu

lo00

~~<c

oo--+

- !T

N

NNN

..-a-

W

OOOw

WW

OOOc

nUuo

00~~

~0oo

---

? ww

w NN

PJ

OLP

DOO

OW

WW

OO

O-J

~~O

CO~~

~oc~

o 6

o~~~

ooo~

~~oo

o~u~

ooo~

~~oc

c

o~%

2ooo

%~o

oo--l

wJoo

ow~o

oo

2 F

~ooo

s%oo

owww

ooo~

~Loo

owww

8ooo

k%~o

ooww

wooo

&~oo

owww

gooo

%%

ooow

wwoo

o~~~

ooow

ww

o8~~

ooo%

~ooo

wwwo

ooww

wooo

www

NNN

oooo

ooo~

PPoo

owww

ooow

wwoo

o

www

NNN

oooo

ooou

-u-lr

ooow

wwoo

owww

ooo

%oo

oKiz

oooM

~ooo

wwwo

oopp

P

~ooo

k%%

ooo%

Booo

wwwo

oo~~

~

~ooo

K8oo

ok%

~ooo

wwwo

oopp

P

wow

NNN

ou-P

~ooo

D~u-

ooow

wwoo

owww

ooo

Page 11: A new three-dimensional connected components algorithm

3-D CONNECTED COMPONENT 217

TABLE 1 Processing Time for 100 x 100 Checkerboard Images

Image size NBANDS

100 X 100 x NBANDS processing time

(CPU set)

2 72.84 4 145.04 8 290.72

16 582.27 32 1147.51

TABLE 2 Processing Time for 25 X 25 Checkerboard Images

Image size

2 4 8

16 32

25 x 25 X NBANDS processing time

(CPU set)

20.38 31.08 56.38

102.72 194.04

REFERENCES I. A. Rosenfeld and J. L. Pfaltz, Sequential operations in digital picture processing, J. Assoc. Comput.

Mach. 12 (4), I%& 471-494. 2. R. Lumia, L. Shapiro, and 0. Zuniga, A new connected components algorithm for virtual memory

computers, Computer Graphics Image Processing, 22, 1983, 287-300. 3. C. M. Park and A, Rosenfeld, Connectivity and genus in three dimensions, Technical Report TR-156,

Computer Science Center, University of Maryland, May 197 1.