# Real-Time Automated Segmentation and Classification of Calcaneal Fractures in CT Images
## 2 Materials and Methods
### Step 2: Segmentation of the Calcaneus Fragments
#### 2.5.2 Contour Detection  
The final step is to use the contour detection algorithm to extract regional boundaries in a calcaneal fracture. The initial value is set to 1 to determine the affiliation of the new contours and other contours. The outer border is the boundary with white pixels (1-component) which are enclosed by the black pixels (0-component). The hole border is the 1-component boundary which is enclosed by the 0-component. The frame is the boundary of the image that is wrapped by 1-component. NBD is the number of contours in the current calculation. LNBD is the last border number encountered when scanning a starting point. Figure 10 shows the connected components and borders in the image.  
Figure 9: (**a**) Tarsal bone detection; (**b**) Calcaneus region; (**c**) Binary image of calcaneus region; and (**d**) Calcaneus region after morphological operations.  
The sub-steps for detection of contour of the calcaneus ROI are as follows:  
1. Find the starting point of the contour Start from the upper-left pixel at location (0,0) of the calcaneus ROI, then the image is scanned row-by-row. This condition indicates that the outer contour that has not been passed as the pixel value is changed in the next contour. Values greater than 1 indicates an 8-connected case that can represent the hole contours that have not been passed.
2. Contour Following Next, start from the starting point that obtained from the previous step. Then the image is scanned row by row and the edges of 1-component is recorded. The square-tracing algorithm [30] is used since it is suitable for 4-connected cases as follows:  
1. If the current pixel value is 1, change the scan direction to the left and move 1 pixel. Conversely, when the pixel value is 0, change the scan direction to the right and move 1 pixel.
2. Continue sub-steps 2a until the current contour point returns to the starting point.  
The outer contour is the contour that passes through the entire contour in different directions. Then, change the pixel value in the following contour procedure. If the neighboring point (\(p+1\), \(q\)) of the current contour point (\(p\), \(q\)) has a pixel value of 0, set the current point to -NBD. In addition, if the current point value is more than 1 NBD, it remains unchanged. Otherwise, it is set to NBD.  
Figure 10: Connected components and borders.  
Build Contour Hierarchies  
The next sub-step is to find out the relationship between contours. NBD that hits the contour during step 1 will be scanned and recorded in LNBD. Each boundary extracted is stored as a point vector which is retrieved and reconstructed with a full hierarchy of nested contours. Then, each contour is encoded with four points. The result is a closed two-dimensional contour for each remaining region as shown in Figure 11a. The contour boundary is a dense set of sequential neighbor points called a blob. A blob larger than 100 pixels is selected and the minimum closing circle is found so that each blob represents one fragment as shown in Figure 11b. The algorithm is shown as follows:  
In transverse and coronal images, if the calcaneus is segmented into a single full blob then it is classified as a normal calcaneus. If the calcaneus is detected as one blob but the area is not full, it is classified as type I (line fracture). Otherwise, the type of fracture is classified by a number of blobs.