The goal of the TCA is to robustly and accurately classify the trackers’ locations from a single CT scan provided at the beginning of the surgery. Once the user takes a CT scan of the patient, that will be the only input needed for the TCA to compute the trackers’ positions as well as the orientation of the tracker. 

TCA Input:  

  • A folder full of CT scans in the DICOM file format. 
  • The folder usually contains between 150-300 slices although the number of slices does not affect the performance of the system. 

Uploading and transforming the input:  

  1. The Python script starts by importing all the necessary libraries.
  2. The user needs to specify the location/path of the folder containing the DICOM files in the Python script. 
  3. The script then automatically recognizes how many files are in the folder and converts all the DICOM files into PNG files as can be seen in Figure 3 and places them into a new folder with a name specified by the user. This is done as PNG files are easier to use with modern image processing libraries and easier to manipulate directly, the pixel relationship is maintained in this relationship. 
  4. While the DICOM files are being transformed, a function will also read one of the DICOM files and print out important parameters of the CT scan such as pixel spacing and slice thickness (mm). This will be done simultaneously with step 3 and is shown in Figure 4. 
Fig3: The created folder with all the converted PNG files.
Fig 3: The created folder with all the converted PNG files.
Figure 4: Shows the outputted slice thickness and pixel spacing.

Pre-processing the images: 

  1. Now that there is a folder of PNGs, the images need to be processed to make the classification algorithm work more accurately and more robustly. Figure 5 shows the image before any preprocessing and after the processing. The image was brightened, converted to grayscale, made binary, and contours will be filled in. 
Figure 5: The Preprocessing Steps

Classifying the Trackers (circles): 

  1. Now that the preprocessing is done and the image is much clearer and more continuous, the circles can begin to be classified. 
  1. A circularity parameter and a circularity threshold are defined, with the threshold being a design choice. The threshold value was found through a trial and error to find the threshold that most accurately and precisely classifies the trackers, the optimal circularity threshold was found to be 0.8. 
  1. Further limits were put on what can be classified as a circle by limiting the area of the circle between 100 and 2000 pixels, which aligns with the physical size of the tracker balls.  
  1. The script has the option to display all the images with the trackers outlined in pink as shown in Figure 6 and prints out/saves the pixel coordinates of the classified trackers as well as their circularity parameter. This also helped in deciding the circularity threshold since it can easily be seen in the output. 
  2. It is important to note that multiple trackers can be seen in the same slice which was a problem early on in the project but by using the circularity method, it’s a matter of the circularity of the circles and not the number of circles so this proved to be a very robust method of recognizing all the circles in a slice no matter how many circles are present as seen in Figure 6. 
Figure 6: Shows the classified circles in the CT slices.

Clustering the Tracker Coordinates: 

  1. Since all the trackers are now classified, the algorithm can be made even more robust by ensuring that a ball appears in multiple scans in a row. 
  1. A circle can be ensured to be a tracker and not an outlier by appearing around the same (𝑥,𝑦) coordinate across adjacent scans. A threshold, which is a design choice, of 6 continuous scans was set for a circle to be considered a tracker and the set of continuous scans was collected and saved in the PNGS folder from earlier, each cluster of images was saved in its own folder.  
  2. Figure 7 shows one of the created clusters and it can be seen how this method ensures with nearly 100% certainty that the trackers are correctly classified. Furthermore, if a scan has more than one tracker, a separate cluster will be made for each tracker. 
  3. Now that the clusters are made, an average of the median 3 slices will give the most precise coordinate for the center of that respective tracker and the output can be simplified to what is shown in Figure 8. 
Figure 7: Shows one of the created clusters.
Figure 8: Shows the final coordinate of the trackers.

Defining Tracker Object, Name & Shape: 

  1. Since different tracker shapes may be used in surgery, each tracker shape must be known and defined in the script.  
  1. A tracker object is defined with an automatically generated name, and a user-inputted tracker shape chosen from a displayed list, and the 4 ball locations are initialized at the origin, these coordinates will be updated in the next step. 
  1. This is an important step as each ball must be classified as ball 1, ball 2, ball 3, or ball 4, as this knowledge will give us the information necessary to understand the orientation of the tracker in relation to its coordinate frame set by the camera.  
  2. As can be seen in Figure 9, there are different tracker shapes, that will need to be inputted into the script so it can successfully classify and differentiate the individual balls into their respective trackers, this is as simple for the user as inputting 1 or 2 into a text box. 
  3. As more tracker shapes are added they can be easily added to the script and the tracker data can be found in the NDI Cygna Camera Software. Figure 9 shows what this looks like in the script for future additions, and Figure 10 shows the output with the initialized coordinates. 
Figure 9: The coordinate frame of two of the trackers, tracker data in the script (mm)
Figure 10: Shows two tracker objects created with two different shapes.

Grouping the Clusters into Trackers: 

  1. All tracker balls are now classified and ready to be grouped into 4’s since all trackers have 4 balls on it. 
  2. The trackers were grouped by knowing that all 4 balls for all trackers lie on a single plane, a script was created to calculate how close to a plane (planarity) a set of 4 balls is, and the top sets of balls that create the highest planarity were chosen and grouped into trackers.  
  3. Figure 11¸ shows the top two planes found by the algorithm and thus the balls were successfully segmented into the correct tracker, the lower the planarity parameter the better and the script has the functionality to print out coordinate combinations, most of the other plenaries were orders of magnitude higher which supports the robustness of this method.  
Figure 11: Output of the coordinates found to lie on the same plane.

Classifying each ball to its number: 

  1. Because of the known relationship of each ball for a given tracker shape, the ball number can be found using a triangulation algorithm. The algorithm used the distance between the balls as well as the angles to determine each ball’s number. The completed TCA with each ball classified and belonging to a tracker can be seen below in Figure 12. 
Figure 12: 3D plot of the two trackers from the CT scan.