CT x-ray scanner
CAT Scanning
I'd like to build a CAT Scanner. It turns out that the software isn't that hard. The algorithm is quite simple. Here are some sample images that illustrate the process. Since I don't yet have the hardware to generate x-ray slices of an object I have synthesized what an x-ray would yield if it scanned an object. These scans are then reassembled to yield the original target image.
In a real Computed Tomography (CT or CaT) system 1-dimensional bands would be recorded of a row of of x-rays that pass through a target. Many different bands are recorded from different angles circling the target. In this demo I don't yet have the x-rays to work with so I work backwards and synthesize the 1D bands from a target image. I then run the process forwards to regenerate the target image. I generate a series of 1D radial bands by rotating the target image and averaging the values in each rows of the image.
Slices are synthesized from a 90 degree rotation of the target image.
The target and four 1-dimensional sections. The position of the sections corresponds to the angle of projection. |
||
Add the four 1D radial sections together (composite overlay) to get the CAT scan image at the right.
The resulting CT image is reminiscent of the target, but it is ambiguous. I found that you need at least 8 sections to get a recognizable image. The more sections you use the better. Here is a CT image made from 8 radial bands:
Here is CT image made from 32 radial sections. 32 seems to be a good number for a CT image at this resolution:
This simple algorithm will work with very complex images. Given a photograph I synthesized 32 1-dimensional scans and then regenerated the photograph using the CT algorithm.
A more complex example
The real world of x-rays is not so simple. In the experiments above, I actually synthesize the radial sections by averaging all the pixels in the rows. This roughly approximates how an x-ray reveals average density of a line through the target. But in the real world there can be materials inside the target that are so dense that they totally block x-ray energy. This reconstruction technique assumes that every part of a target is at least somewhat transparent. If there are parts of a target that are totally opaque even to x-rays then this will result in ambiguous, hidden sections. These hidden sections not only hide what is inside of them, but they also cause shadows that distort areas outside.
The following target is similar to the one used before except that it now has a screen added. The algorithm that synthesizes the radial sections was modified to treat any red are as totally opaque. The result is that anything inside the cup shaped screen is totally hidden. The dense area also throws off the contrast so that it is difficult to see the notch at the top of the target, but you can more or less make it out.
Image processing
The image that results from the composite of the 1D sections has very low contrast. It is simple to expand the dynamic range of the image, but also note that the contrast is weighted towards the center. This is because the radial sections favor the center of the image. The center of the target has the most overlapping sections so the pixels near the center contribute more signal to the average. It's difficult to apply a uniform contrast enhancement over the entire image because the result will leave the edges too dark or the center too light. What is needed is contrast enhancement that will be weighted based on the distance from the center of the image.
Source code
This is a rough draft of the source code written in Python. It requires the PIL module for image manipulation.
Click here to download: cat_scanner.py <include src="/home/noahspurrier/noah.org/engineering/src/python/x-ray_cat_scan/cat_scanner.py" highlight="python" />