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:
- The Python script starts by importing all the necessary libraries.
- The user needs to specify the location/path of the folder containing the DICOM files in the Python script.
- 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.
- 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.
Pre-processing the images:
- 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.
Classifying the Trackers (circles):
- Now that the preprocessing is done and the image is much clearer and more continuous, the circles can begin to be classified.
- 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.
- 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.
- 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.
- 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.
Clustering the Tracker Coordinates:
- 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.
- 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.
- 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.
- 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.
Defining Tracker Object, Name & Shape:
- Since different tracker shapes may be used in surgery, each tracker shape must be known and defined in the script.
- 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.
- 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.
- 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.
- 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.
Grouping the Clusters into Trackers:
- All tracker balls are now classified and ready to be grouped into 4’s since all trackers have 4 balls on it.
- 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.
- 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.
Classifying each ball to its number:
- 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.