When labeling is performed for a three-dimensional image, the present
invention aims to reduce time required for labeling in the
three-dimensional image by three-dimensionally referring connection
relationships among image areas. To achieve this object, the following
processing is performed. A variable i of label number is initialized to 1
(step S901), and pixels whose pixel value is 1 are searched for (step
S902). The first time that a pixel whose pixel value is 1 is detected
(step S903), the label number of the pixel is set to i (1) (step S904).
When the next pixel (target pixel) whose pixel value is 1 is detected
(step S905), if plural pixels having label numbers are detected within a
three-dimensional neighboring mask, the smallest label number is assigned
as the label number of the target pixel (step S907). If one pixel is
detected, the label number is assigned as the label number of the target
pixel. If all pixel values (except the target pixel) within the
three-dimensional neighboring mask are 0, a label number (i+1) is
assigned as the label number of the target pixel (step S909).