An Efficient Connected-Component Labeling Algorithm for 3-D Binary Images

Conventional voxel-based algorithms for labeling connected components in 3D binary images use the same mask to process all object voxels. To reduce the number of times that neighboring voxels are checked when object voxels are processed, we propose an algorithm that uses two different masks for processing two different types of object voxels. One type of mask is used when the voxel preceding the object voxel being processed is an object voxel, and the other type is used otherwise. In either case, an optimal order is used for checking the voxels in the corresponding mask. Experimental results demonstrate that our proposed algorithm checked fewer voxels, and was more efficient than conventional algorithms.

Connected-Component labeling (CCL) in a binary image is indispensable for pattern recognition, pattern analysis, computer (robot) vision, and machine intelligence [1]. CCL can transform a binary image to a symbolic image in which all pixels belonging to a connected component (also called an object) are assigned a unique label. Subsequently, using the symbolic image, the features of these connected components (objects) can be extracted.
He et al. [21] presented an efficient voxel-based CCL algorithm for 3D binary images (for convenience, we call this algorithm the VCL algorithm). By checking the voxels in the mask in an optimal order, the VCL algorithm can reduce the number of voxels to check when processing each object voxel. However, some voxels that were already checked earlier while processing another voxel may be checked again.
An effective strategy for improving 2D CCL algorithms is to reuse the information obtained while processing each object pixel to reduce the number of pixels that need to be checked when processing another object pixel later. This strategy was first presented in [24], further studied in [3], and has also been extended to block-based CCL algorithms [25], [26].
This article presents an improvement of the VCL algorithm that incorporates the above efficient strategy in the following manner: for an object voxel that follows another object voxel, the algorithm uses the mask M1, which contains much fewer voxels than the conventional mask. Conversely, for an object voxel that follows a background voxel, it uses another mask M2, which is like the mask used in conventional voxel-based CCL algorithms. In either case, an optimal order is used for checking the voxels in the corresponding mask.
The remainder of the article is organized as follows. We present some preliminaries in Section II and introduce our proposed algorithm in Section III. In Section IV, we present experimental results to evaluate the performance of our proposed algorithm against conventional CCL algorithms. We discuss the results in Section V and present our concluding remarks in Section VI.

II. PRELIMINARIES
For a 3D binary image of size U × V × W, we use v(x, y, z) to denote the voxel at (x, y, z) in the image, where 1 ≤ x ≤ U, 1 ≤ y ≤ V, and 1 ≤ z ≤ W. For convenience, we also use v(x, y, z) to denote the value of the voxel. Without loss of generality, we use 0 as the value of a background voxel and 1 as the value of an object voxel. We only consider 26-connectivity in this article because the other cases (i.e., 6-connectivity and 18-connectivity) are sub-cases of 26-connectivity. Moreover, all border voxels of an image are assumed to be background voxels.

A. PRINCIPLE OF LABEL-EQUIVALENCE-BASED TWO-SCAN LABELING ALGORITHMS
For a voxel v(x, y, z), the 26 voxels v(x ± i, y ± j, z ± k) such that i, j, k are 0 or 1, except i = j = k = 0, are said to be its neighbors. Two object voxels p and q in a binary image are said to be 26-connected if and only if there is a path that consists of object voxels v 1 , …, v n such that v 1 = p, v n = q, and for 1 ≤ i < n, v i and v i+1 are neighbors of each other. A connected component (an object) in a binary image is a maximum set of object voxels in the image such that all pairs of voxels in the set are 26-connected.
To label a binary image, a label-equivalence-based twoscan labeling algorithm [2] works as follows. In the first scan, for each voxel v(x, y, z), if v(x, y, z) is a background voxel, it does nothing; otherwise (i.e., v(x, y, z) is an object voxel), it checks whether there is any object voxel in the mask M, which consists of the 13 neighbors of v(x, y, z) that have been processed (Fig. 1). If there are none, the algorithm assigns v(x, y, z) a new provisional label. Otherwise, there are some object voxels in the mask, each of which has been assigned a provisional label during the previous image processing. Because all object voxels in the mask are 26-connected to v(x, y, z), all object voxels in the mask and v(x, y, z) belong to the same object. Therefore, the algorithm assigns any label in the mask to v(x, y, z), records all labels in the mask as equivalent labels, and finds a unique label as the representative of the equivalent labels by resolving equivalent labels.
In this manner, after the first scan, each object voxel has been assigned a provisional label, all provisional labels assigned to the voxels of each object have been recorded as equivalent labels, and a representative label for each group of equivalent labels has been found by resolving equivalent labels. In the second scan, by replacing the provisional label of each object voxel by its representative label, all voxels of an object are assigned a unique label.

B. EQUIVALENT-LABEL-SET STRATEGY FOR LABEL EQUIVALENCE RESOLUTION
The equivalent-label-set strategy is the most efficient strategy for resolving label equivalences [2]. This strategy combines all equivalent provisional labels in a set and uses the smallest label in the set as the representative label of all labels in the set [23]. For convenience, we use R(l) to denote the representative label of the provisional label l, and S(t) to denote the equivalent label set for which t is the representative label. Thus, for each provisional label x ࢠ S(t), R(x) = t holds.
In the first scan, when a new provisional label l is assigned to an object voxel v (i.e., v = l), this strategy sets the representative label of l to itself (i.e., R(l) = l) and establishes a new equivalent label set S(l) = {l}. Whenever two provisional labels m and n are found to be equivalent, where m ࢠ S(u) and n ࢠ S(v), all provisional labels in S(u) and S(v) are equivalent. Therefore, S(u) and S(v) are combined by the following procedure resolve (u, v).
Using this strategy, at any time in the first scan, all provisional labels assigned to a connected component in the processed area of the image are combined in an equivalent label set whose smallest label is their representative label. Therefore, as soon as the first scan has finished, all equivalent labels assigned to an object are combined in an equivalent label set whose smallest label is the representative label of the object.

C. REVIEW OF VCL ALGORITHM
The VCL algorithm is a label-equivalence-based two-scan algorithm that uses the equivalent-label-set strategy for label equivalence resolution. In principle, when processing each object voxel, the voxels in the mask can be checked in any order. However, the order of checking may affect the efficiency. Because there are 13 voxels in the mask, the number of possible orders is 13! therefore, it is important to find an optimal order for checking the voxels in the mask.
According to the principle of the equivalent-label-set strategy for label equivalence resolution, when processing an object voxel, each object voxel in the mask has been assigned a provisional label, and all provisional labels assigned to the voxels of each connected part in the mask have been combined in the same equivalent label set during the previous image processing. That is, all label equivalences between the provisional labels of each connected part in the mask have been resolved. Therefore, only the label equivalences between different connected parts in the mask need to be considered.
When checking a voxel in the mask, if the voxel is an object voxel, that voxel and all its neighbors in the mask certainly belong to the same connected part; therefore, it is not necessary to check any of its neighbors further. For this reason, when the VCL algorithm processes an object voxel, it checks voxels in the mask in the order of the numbers of their neighboring voxels in the mask. The number of neighbors of each voxel in the mask shown in Fig. 1 is shown in Table 1. According to Table 1, to process an object voxel, the VCL algorithm checks voxels in the mask in the order (named Order- The VCL algorithm labels a 3D binary image as follows. In the first scan, if the current voxel is a background voxel, it does nothing. Otherwise (i.e., if the current voxel is an object voxel), it checks its neighbors in the mask in Order-I. If v 9 is an object voxel, the provisional label of v 9 is assigned to the current voxel. Because v 9 connects with all other object voxels in the mask (if any), no label equivalence needs to be considered. Conversely, if v 9 is a background voxel, then v 3 is checked. If v 3 is an object voxel, the provisional label of v 3 is assigned to the current voxel. Because there may be label equivalences between the provisional label of v 3 and other object voxels in the mask, caused by the existence of the current object voxel, the other voxels in the mask except the neighbors of v 3 (i.e., v 11, v 12 , and v 13 ) should be checked further.
In the case in which v 3 is also a background voxel, v 6 is the next voxel in Order-I. The procedure for processing v 6 is like that described above. Other cases can be processed in a similar manner.
Experimental results have demonstrated that the VCL algorithm is much more efficient than previous labeling algorithms for 3D binary images [21]. However, some voxels in the mask that have been checked when processing another object voxel earlier may be checked again. Therefore, the VCL algorithm may perform substantial redundant work, which should be avoided.

III. PROPOSED ALGORITHM
As noted above, the VCL algorithm uses the same order to check the voxels in the mask when it processes all object voxels. When processing an object voxel v that follows another object voxel u, some voxels in the mask that were checked when processing u may be checked again when processing v. This increases the time for checking voxels and therefore decreases the efficiency of CCL. To solve this problem, we propose an improved VCL algorithm that uses the information obtained while processing an earlier object voxel to label the current object voxel.

A. PROCESSING AN OBJECT VOXEL FOLLOWING ANOTHER OBJECT VOXEL
When the algorithm processes an object voxel v that follows another object voxel u, it can assign the provisional label of v 1 (u) to v. To resolve the related label equivalences, of the 13 processed neighbor voxels of v, the nine voxels v 1 (u), v 2 (u 3 ), v 3 (u 4 ), v 5 (u 6 ), v 6 (u 7 ), v 8 (u 9 ), v 9 (u 10 ), v 11 (u 12 ), and v 12 (u 13 ) are also the neighbors of u, as shown in Fig. 2. Therefore, all label equivalences (if any) related to these nine voxels have already been resolved while processing u. To process v, the provisional label of u needs to be assigned to v, and the label equivalences (if any) caused by the remaining neighbors of v (i.e., v 4 , v 7 , v 10 , and v 13 ) need to be resolved. Accordingly, the mask M1 for processing v consists of v 4 , v 7 , v 10 , and v 13 , as shown in Fig. 3.
The voxels u 3 (v 2 ), u 4 (v 3 ), u 6 (v 5 ), u 7 (v 6 ), u 9 (v 8 ), u 10 (v 9 ), u 12 (v 11 ), and u 13 (v 12 ) may have been checked while processing u. Therefore, when processing v, the information known about these voxels can be used to resolve the related label equivalences. According to how the information to be used, there are the following five cases, where resolve(u, v) is the label equivalence resolution procedure (between u and v) defined in Section II-B.
a) In the case in which u 10 = 1 (i.e., v 9 = 1; see Fig. 2), because v 9 connects to v and to each of v 4 , v 7 , v 10 , and v 13 , all related label equivalences (if any) in the mask M1 have been resolved; therefore, no new label equivalence needs to be resolved. b) In the case in which [(u 10 , v 10 , and v 13 all connect to u and v; therefore, no new label equivalence needs to be resolved. c) In the case in which [(u 10 and v 10 connect to u and v, but v 13 does not. Therefore, only v 13 needs to be checked.
, v 13 and v 10 connect to u and v, but v 4 and v 7 do not. Therefore, In the other cases, because there is less available information, it is less helpful and can be ignored. In such cases, if v 9 = 1, because v 9 connects to v 1 (u) and all v 4 , v 7 , v 10 , and v 13 , no new label equivalence needs to be resolved. Therefore, checking v 9 first is efficient. Conversely, if v 9 = 0, the voxels in mask M1 are checked in the order decided by the strategy in the VCL algorithm. Because the numbers of neighbors of v 4 , v 7 , v 10 , and v 13 in the mask M1 are 2, 2, 3, and 1, respectively, the optimal order (named Order-II) for checking these voxels is v 10 → (v 4 , v 7 ) → v 13 . The procedure for resolving label equivalences in these cases will be given latter. The information of checked voxels in each of the above cases will be recursively used to process the following object voxel w (if it is). The case for processing w will be also one of Case (a)-Case (e).
In Case (a), we only know v 9 = 1, i.e., w 8 = 1 (see Fig. 2, similarly hereinafter). Thus, it is Case (e) for processing w. In Now, we consider the procedure for processing v in Case (e). As introduced above, v 9 (i.e., u 10 /w 8 ) will be checked first. If v 9 = 1, the same as in Case (a), nothing needs to be done. Moreover, if w = 1, for processing w, it will be Case (e). On the other hand, if v 9 = 0, v 10 (i.e., u 11 /w 9 ) will be checked. If v 10 = 1, resolve(v, v 10 ) will be executed. If w = 1, for processing w, it will be Case (a). Other situations can be analyzed in a similar way. The procedure for Case (e) (named Procedure I) can be described as follows.
The operations for processing v in the various cases are summarized in Table 2, where "e" means either a background voxel or an object voxel, and w is the next voxel of v. The case transition is shown in Fig. 4. More details are given in Appendix.

B. PROCESSING AN OBJECT VOXEL FOLLOWING A BACKGROUND VOXEL
When processing an object voxel u following a background voxel, all processed neighbor voxels of u except for u 1 (i.e., u 2 , …, u 13 ), as shown in Fig. 2, are unknown voxels. Therefore, the mask M2 for processing u in this case consists of u 2 , …, u 13 , as shown in Fig. 5.
Our proposed algorithm decides the order in which to check the voxels in M2 according to the following two strategies.   The first strategy is the same as that in the VCL algorithm: a voxel with more neighbors should be checked earlier. The number m of neighbors of each voxel in the mask for processing u is shown in column 2 of Table 3.
The second strategy is based on the following consideration. In the case in which the next voxel v to be processed is also an object voxel, as described in Section III-A, the information on u 4 , u 7 , u 10 , and u 13 obtained while processing u can be used to reduce the number of voxels to check when processing v. Therefore, these voxels should be checked preferentially. Obviously, a voxel with more neighbors from the set {v 4 , v 7 , v 10 , v 13 } should be checked earlier. The number of neighbors from {v 4 , v 7 , v 10 , v 13 } of each voxel in the mask for processing u is shown in column 3 of Table 3. Combining the above two strategies, the voxels in the mask for processing v should be checked in descending order of the value s = m + 0.5 × n, as shown in column 4 of Table 3. Here, 0.5 is a weighting coefficient inspired by the observation that the next voxel v may be a background voxel. Thus, the order for checking the voxels in the mask for processing u (named The procedure for labeling an object voxel can be defined in a similar way to that of the VCL algorithm.

C. PROCEDURE OF PROPOSED ALGORITHM
In the first scan, the algorithm does nothing for any of the background voxels. For an object voxel following a background voxel, the voxels in mask M2 (shown in Fig. 5) are checked in the order Order-III, and the related label equivalences (if any) are resolved. Then, each following object voxel is processed according to the information about the voxels checked while processing the previous object voxel, as introduced in Section III-A. An illustration of the first scan of our proposed algorithm, LabelProcessing, is presented in Appendix.
In the second scan, the provisional label of each object voxel is replaced by its representative label, similarly to the VCL algorithm.

IV. EXPERIMENTAL RESULTS
In this section, we compare our proposed algorithm with VCL and RCL, which is a run-based algorithm for labeling 3D images [21]. The code of the VCL and RCL algorithms was provided by their authors.
All three algorithms were implemented in the C language. All experiments were executed on a PC-based workstation (Intel Xeon CPU E5-1650 v4 @ 3.60 GHz, 4 GB RAM, Ubuntu Linux OS), and were compiled by the GNU C compiler (version 5.16) with the -O3 option. All execution times reported in this section were obtained with the use of one core. All reported results were obtained by averaging the results of 1000 runs.

A. EXPERIMENTAL RESULTS ON NOISE IMAGE SETS
Five sets of 41 uniform noise images, of five different sizes (163 × 163 × 163, 327 × 327 × 327, 408 × 408 × 408, 465 × 465 × 465, and 512 × 512 × 512 voxels) were generated by thresholding images containing uniform random noise with 41 different threshold values (from 0 to 1000 in steps of 25). Because such noise images contain connected components with complicated geometric shapes and complex connectivity, they pose a severe challenge to CCL algorithms.
For the noise images of each size, the maximum and average execution times are shown in Fig. 6. As Fig. 6 shows, as the image size increased, the execution time of all three algorithms increased similarly, and our proposed algorithm was the most efficient of the algorithms with respect to both maximum and average execution time.
We used all noise images of size 512 × 512 × 512 to evaluate how the execution time varied with the density of the object voxels in an image. The execution times are shown in Fig. 7. The results show that our proposed algorithm was more efficient than the VCL algorithm on noise images with densities between 0.3 and 0.9, and was more efficient than the RCL algorithm on all tested images except those with the lowest and highest densities. Fig. 8 shows the speed improvement of our proposed algorithm compared with the VCL and RCL algorithms. The speed improvement compared with VCL is plotted as S1 (= (T VCL -T Ours ) / T VCL ), and that compared with RCL is plotted as S2 (= (T RCL -T Ours ) / T RCL ).

B. EXPERIMENTAL RESULTS ON OVERLAPPED-CUBE IMAGE SET
The overlapped-cube image set is composed of images of size 512 × 512 × 512 containing a random distribution of 50 cubes of object voxels, where overlapping cubes are allowed, with cube sizes ranging from 10 × 10 × 10 to 100 × 100 × 100 in steps of 5. The densities of these images range from 0.59% to 85.5%.
The execution times of the algorithms on the overlappedcube image set are shown in Fig. 9. For almost all the overlapped-cube images, our proposed algorithm was much more efficient than both the VCL and RCL algorithms, particularly for larger cubes. The average speed improvements of our proposed algorithm compared with the VCL and RCL algorithms were 15% and 12%, respectively.

C. EXPERIMENTAL RESULTS ON MEDICAL IMAGES
Two 3D medical images, which were downloaded from a dataset in the University of North Carolina Volume Rendering Test Data Set archive, were used in our experiments. One is a CT head image (named CThead), and the other is an MR brain image (named MRbrain). The size of both images is 256 × 256 × 99. Slices of CThead and MRbrain are shown in Fig. 10(a) and (b), respectively. The two images were binarized by using the optimal threshold obtained by the MATLAB graythresh function.
The execution times of the algorithms on the two medical images are presented in Table 4. The table shows that our proposed algorithm is more efficient than both the VCL and RCL algorithms, on both images.

D. EXPERIMENTAL RESULTS COMPARED WITH PRED++_3D ON YACCLAB
An efficient algorithm for labeling 3D binary images, named PRED++_3D, has recently been proposed [16]. This algorithm is also voxel-based and uses the same mask as that used in the VCL algorithm. By using the optimal decision tree, state prediction, and code compression, PRED++_3D performs better than LED_3D, a variant of the VCL algorithm.
We compared our proposed algorithm with the LED_3D and PRED++_3D algorithms on the Yet Another Connected Components Labeling Benchmark (YACCLAB) [27], [28], which is a widely used open-source C++ benchmarking framework for CCL algorithms. The code of the PRED++_3D and LED_3D algorithms was downloaded from https://github.com/prittt/YACCLAB. The code of our proposed algorithm was modified to adapt it to YACCLAB.
The execution times (which were obtained by averaging 50, 10, and 100 runs on Mitochondria, OASIS, and Hilbert, respectively) are shown in Fig. 12. For OASIS, Fig. 12 shows only the execution times on the 30 images from images. This is because the execution times on the remaining images are similar to those shown in Fig. 12(b). Fig. 12 shows that, for the first two datasets, our proposed algorithm was faster than both the LED_3D and PRED++_3D algorithms, particularly on the Mitochondria dataset. On the third dataset, our proposed algorithm is faster than the other two algorithms on all images except n06.

A. COST EFFECTIVENESS ANALYSIS
The VCL algorithm and our proposed algorithm perform CCL in a similar manner. In the first scan, for each object voxel, both algorithms assign the voxel a provisional label, record all provisional labels in the mask as equivalent, and resolve label equivalences among these provisional labels.
In the second scan, both algorithms replace each provisional label by its representative label. Therefore, the two algorithms have the same time complexity. The reason that our proposed algorithm performs better than the VCL algorithm is that our proposed algorithm checks fewer voxels than the VCL algorithm.
For each object voxel being processed, the VCL algorithm checks the voxels in mask M (shown in Fig. 1) in Order-I (defined in Section II-C). As explained in [21], when processing an object voxel, it considers 25 configurations of the mask. For each configuration, the number of times that a voxel in the mask is checked is shown in Table 5, in which "b," "o," "e," and "-" mean "background voxel," "object voxel," "either," and "irrelevant voxel," respectively. An irrelevant voxel is one that does not need to be checked because whether it is an object voxel does not affect the result. An "e" voxel does need to be checked, and it could be either an object voxel or a background voxel.

TABLE 7. Number of Neighbors to be Checked for Each Configuration in Mask M1 in Our Proposed Algorithm
The number of times that neighbors are checked in case i, denoted by N i , is shown in the rightmost column of Table 5, where 1 ≤ i ≤ 25. The probability of being case i, denoted by p i , is k/W, where W is the number of all configurations of the mask and k is the number of configurations in case i. For example, p 1 = 2 12 /2 13 = 0.5 and p 5 = 2 9 /2 13 = 0.0625. Thus, for the VCL algorithm, the average number of times that it checks voxels when it processes an object voxel is 25 i=1 p i N i = 3.17. When our proposed algorithm processes an object voxel v, if the previous voxel is a background voxel, it processes v by using the mask M2 (shown in Fig. 5) and checks the voxels in the mask in Order-III (defined in Section III-B). As shown in Table 6, 23 configurations of the mask need to be considered. For each configuration, the number of times that voxels in the mask are checked is shown in the rightmost column of Table 6. The average number of times that voxels are checked is 23 i=1 p i N i = 3.11. If the voxel preceding v is an object voxel u, our proposed algorithm processes v by using the mask M1 (shown in Fig. 3) and checking the voxels in the mask in Order-II (defined in Section III-A). The cases to be considered are listed in Table 7.
Here, u i and v j are as defined in Fig. 2, "c" means "checked voxel" (i.e., the voxel has been checked while processing the previous object voxel), and "n" means "not checked" (i.e., the voxel has not been checked while processing the previous object voxel). For each case, the number of times that voxels in the mask are checked is shown in the rightmost column of Table 7.
If u 10 (v 9 ) has been checked while processing the previous object voxel u (v 1 ), one of the cases from case 1 to case 10 holds. The probability of being case i, p i , can be calculated as explained above. In this situation, the average number of times that voxels are checked is 10 i=1 p i N i = 0.42. If u 10 (v 9 ) has not been checked while processing the previous object voxel u (v 1 ), one of the cases from case 11 to case 14 holds. In this situation, the algorithm checks some or all of v 9 , v 10 , v 7 , v 4 , and v 13. The probability of being case i, p i , can also be calculated as explained above. The average number of times that voxels are checked is 14 i=11 p i N i = 2.13. According to Table 7, the probability that u 10 (v 9 ) is checked while processing u is 0.5. Therefore, when processing an object voxel following another object voxel by using the mask M1, the average number of times that voxels are checked is 0.5 × 0.42 + 0.5 × 2.13 = 1.27.
Suppose that M1 and M2 are used equivalently; then, to process an object voxel, the average number of times that voxels are checked by our proposed algorithm is 0.5 × 3.11 +0.5 × 1.27 = 2.19. Because 2.19 is less than 3.17 (the average number of times that voxels are checked when the VCL algorithm processes an object voxel), our proposed algorithm checks fewer voxels than the VCL algorithm. Therefore, our proposed algorithm is more efficient than the VCL algorithm.
We used all the 512 × 512 × 512 noise images to count the numbers of voxels checked by the VCL algorithm, the CML algorithm (which is a variant of our proposed algorithm that uses only m, shown in Table 3, to decide the order for checking the voxels in the mask M2), the PRED++ algorithm, and our proposed algorithm. The results are shown in Fig. 13, which shows that our proposed algorithm checks fewer voxels than the other three algorithms for all images. This is the reason that our proposed algorithm is more efficient than the conventional algorithms.

B. COMPARISON OF IMPLEMENTATION ARCHITECTURE AND FLOW
The first scan of our proposed algorithm is an improvement of that of the VCL algorithm. The VCL algorithm processes all object voxels in the same manner, and therefore its implementation architecture is very simple. The processing flow is shown in Fig. 14, where W is the size of the input image. In contrast, our proposed algorithm processes object voxels differently, depending on whether they follow a background voxel or another object voxel. Moreover, when our proposed algorithm processes an object voxel following another object voxel, it uses the information obtained while processing the previous object voxel, and the information gathered while processing this object voxel is used to process the following object voxel (if it is one). The cases (a)-(e) shown in Table 2 demonstrates how to process an object voxel based on the information of already checked pixels when Mask M1 is used, and the case transition diagram shown in Fig. 4 shows the case transition when successive object voxels are processing. Because recursion is necessary to implement our proposed algorithm, the implementation architecture of our proposed algorithm is much more complex than that of the VCL algorithm (see Appendix.).

C. COMPARISON WITH PRED++_3D ALGORITHM
Similar to our proposed algorithm, when processing object voxels, the PRED++_3D algorithm also uses known information for state prediction. However, PRED++_3D uses the same mask as that used in the VCL algorithm to process all object voxels, whereas our proposed algorithm uses two different masks for processing two different types of object voxels.
In addition to the two masks, our proposed algorithm introduces two new improved strategies. The first strategy is a method to decide the order in which to process voxels in the mask when processing the object voxels that follow a background voxel. The second strategy is to ignore voxels that do not provide information for processing an object voxel that follows another object voxel. The latter improvement reduces the number of cases to be considered; moreover, in such cases, an efficient procedure (i.e., Procedure I, presented in Section III-A) is used, which checks the voxel above the current object voxel first.
Because of these improvements, our proposed algorithm performed better than PRED++_3D.

D. LIMITATION OF PROPOSED ALGORITHM
According to the analysis in Section V-A, when processing an object voxel following a background voxel, the average numbers of times that voxels in the corresponding mask are checked by the VCL algorithm and our proposed algorithm are 3.17 and 2.19, respectively; these numbers are very similar. For a low-density noise image, the voxel preceding an object voxel is very likely to be a background one. Therefore, the efficiencies of the VCL algorithm and our proposed algorithm are almost the same for low-density noise images (with densities between 0.0 and 0.3).
Conversely, when processing an object voxel v(x, y, z), both the VCL algorithm and our proposed algorithm first check the voxel above v(x, y, z) (i.e., v(x, y, z-1)), and do nothing to resolve label equivalences if v(x, y, z-1) is an object voxel. Therefore, for high-density noise images (with densities greater than 0.9), in which the voxel above the object voxel being processed is very likely to be an object voxel, the efficiencies of the two algorithms are also almost the same.
This analysis indicates that our proposed algorithm has no advantage for processing very low-density or very highdensity images. This is the main limitation of our proposed algorithm.
Additionally, as noted in Section V-B, the source code of our proposed algorithm is much longer than that of the VCL algorithm, and our proposed algorithm contains recursive procedures, whereas the VCL algorithm does not. Usually, a longer and recursive program requires more execution time. This may be the reason that the execution time on noise images is not completely proportional to the number of times that voxels are checked.

VI. CONCLUSION
In this article we proposed an efficient CCL algorithm for 3D binary images. Our proposed algorithm uses two different masks for processing object voxels, depending on whether the voxel preceding the object voxel being processed is an object voxel. In either case, the algorithm checks the voxels in the corresponding mask in an optimal order. Experimental results demonstrate that our proposed algorithm checked fewer voxels than the VCL algorithm for all 3D binary images tested, and that our proposed algorithm was more efficient than the VCL and RCL algorithms for almost all noise images, the overlapped-cube image set, and the medical images. Experimental results on YACCLAB also demonstrated that our proposed algorithm was more efficient than the PRED++_3D algorithm.
Our research results can play an important role in many applications, such as detecting the number and volume of blood clots in blood vessels, detecting the number and volume of crystals in material experiments, and determining the volume of materials required for 3D printers by calculating the volumes of parts. In future work, we will construct a hardware implementation and parallel implementation of the algorithm. We will also try to use the strategies proposed in [16] to automatically generate and compress the code of our proposed algorithm, which may improve its speed further.

ACKNOWLEDGMENTS
We thank the anonymous referees for their valuable comments, which greatly improved this article. We are grateful to the associate editor, Prof. Song Guo, for his kind cooperation.  China, in 1986, and the M.S. and Ph.D. degrees in AI and computer science from the Nagoya Institute of Technology, Nagoya, Japan, in 1994 and 1997, respectively. He is currently a Professor with Aichi Prefectural University, Nagakute, Japan, and a Guest Professor with the Shaanxi University of Science and Technology, Xi'an. From 2006 to 2007, he was with the University of Chicago, Chicago, IL, USA, as a Research Associate. His research interests include intelligent image processing, computer vision, automated reasoning, pattern recognition, string searching, and artificial intelligence.