Difference between revisions of "CT x-ray scanner"

From Noah.org
Jump to navigationJump to search
m
Line 13: Line 13:
 
In a modern [http://en.wikipedia.org/wiki/Computed_tomography Computed Tomography (CT or CaT)] system an x-ray emitter and a 1-dimensional detector band is rotated 360 degrees with the target in the middle. The detector band records how much the target attenuates the x-rays at different angles. A series of these snapshot recordings are saved at regular intervals. The series of 1-dimensional bands are used to reconstruct the 2-dimensional plane that intersects a projection of each bands. The number of bands in the series can vary. The more that are recorded, the better the reconstruction. The most common method is called [http://en.wikipedia.org/wiki/Filtered_back_projection filtered back projection]. This is an easy algorithm to implement. Seeing the original reconstructed from a series of projections is rather magical. It seems too easy, but you get what you pay for. Filtered back projection suffers from a number of flaws including artifacts, ambiguous reconstruction shadows, and sensitivity to noise and missing data. No method is perfect, but there are alternatives which are better than filtered back projection. One alternative method is called [http://en.wikipedia.org/wiki/Iterative_reconstruction iterative reconstruction]. This method is much more complex and computationally expensive than filtered back projection, but it deals better with noise, incomplete data, and it produces fewer artifacts. There are many algorithms that follow the iterative reconstruction method. One example is [http://en.wikipedia.org/wiki/Algebraic_reconstruction_technique Algebraic reconstruction].
 
In a modern [http://en.wikipedia.org/wiki/Computed_tomography Computed Tomography (CT or CaT)] system an x-ray emitter and a 1-dimensional detector band is rotated 360 degrees with the target in the middle. The detector band records how much the target attenuates the x-rays at different angles. A series of these snapshot recordings are saved at regular intervals. The series of 1-dimensional bands are used to reconstruct the 2-dimensional plane that intersects a projection of each bands. The number of bands in the series can vary. The more that are recorded, the better the reconstruction. The most common method is called [http://en.wikipedia.org/wiki/Filtered_back_projection filtered back projection]. This is an easy algorithm to implement. Seeing the original reconstructed from a series of projections is rather magical. It seems too easy, but you get what you pay for. Filtered back projection suffers from a number of flaws including artifacts, ambiguous reconstruction shadows, and sensitivity to noise and missing data. No method is perfect, but there are alternatives which are better than filtered back projection. One alternative method is called [http://en.wikipedia.org/wiki/Iterative_reconstruction iterative reconstruction]. This method is much more complex and computationally expensive than filtered back projection, but it deals better with noise, incomplete data, and it produces fewer artifacts. There are many algorithms that follow the iterative reconstruction method. One example is [http://en.wikipedia.org/wiki/Algebraic_reconstruction_technique Algebraic reconstruction].
  
In this demo I start with a target image; I synthesize a series of 1-dimensional projections of the target image at different angles; and finally I reconstruct an approximation of the original target image. The reconstruction is done simply overlaying the projections over each other.
+
In this demo I synthesize a set of 1-dimensional projections of a target image at different angles, then I reconstruct an approximation of the original target image.
  
Transforming a target into a set of 1-dimensional projections of average density is called the [http://en.wikipedia.org/wiki/Radon_transform Radon transform]. Each 1-dimensional projection in the Radon transform is constructed by averaging the target's density along parallel lines at a given angle. In our case, "density" is the pixel's brightness in the target image. The Radon transform is related to the CT scanner's recordings of x-ray beam attenuation. In fact, a CT scanner creates a Radom transform of a target. The one fine point here is that an x-ray image is a recording of x-ray beam attenuation through a target. Beam attenuation is exponential, so to make it equivalent to a density projection we need to take the log of x-ray recordings. I use the Radon transform to simulate the recordings 1-dimensional projections I would get from a CT scanner.  
+
[http://en.wikipedia.org/wiki/Johann_Radon Johann Radon] defined a transform that for a given target gives a set of 1-dimensional projections of the average of the target's density along lines parallel to a given angle. This transform is called the [http://en.wikipedia.org/wiki/Radon_transform Radon transform]. In our case, the target's "density" is the pixel's brightness. The set of 1-dimensional projections is called a "sinogram", and is graphed along an axis for the angle each 1-dimensional projection.
  
Johann Radon also showed that you can reconstruct the original with an inverse Radon transform. If you graphed a each 1-dimensional projection along an axis that measures the angle of the projection then you get a graph called a "sinogram".
+
The Radon transform is related to the CT scanner's recordings of x-ray beam attenuation. In fact, a CT scanner creates a Radom transform of a physical target. One minor distinction to note is that the value of an x-ray beam attenuation through a target is exponential. To make the x-ray recordings equivalent to a Radon transform density projection you would need to take the log of the recorded x-ray values. I use the Radon transform to simulate the set of 1-dimensional projections I might get from a CT scanner. Since I'm generating the Radon transform directly from the image, not using real x-ray recordings, I don't need to take the log of the values.
  
In this samples slices are synthesized from a 90 degree rotation of the target image.
+
Johann Radon also showed that if you have a "sinogram" of a target then you can reconstruct an approximation of the original target with an inverse Radon transform. This simply overlays each 1-dimensional projection over each other.
 +
 
 +
In the following example the 1-dimensional projections of the target are made from only 90 degree rotations of the target image.
  
 
{| border="0"
 
{| border="0"
|+ Relative position of each scan slice
+
|+ Each projection is located at the angle relative to the target from which it was generated.
 
|-
 
|-
 
|
 
|
Line 29: Line 31:
 
  The position of the
 
  The position of the
 
  sections corresponds to
 
  sections corresponds to
  the angle of projection.
+
  the angle of projection relative to the target..
 
| [[image:target.png]] || [[image:section_4_0.png]]
 
| [[image:target.png]] || [[image:section_4_0.png]]
 
|-
 
|-
Line 35: Line 37:
 
|}
 
|}
  
Add the four 1D radial sections together (composite overlay) to get the CT scan image at the right.
+
After adding the four 1-dimensional projections together (composite overlay) you get the following CT image:
  
 
[[image:section_4_0.png]]+[[image:section_4_3.png]]+[[image:section_4_2.png]]+[[image:section_4_1.png]] = [[image:target_4_out.png]]
 
[[image:section_4_0.png]]+[[image:section_4_3.png]]+[[image:section_4_2.png]]+[[image:section_4_1.png]] = [[image:target_4_out.png]]
  
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:
+
As you can see, using only 90 degree projections does not give very good results. The more sections you use the better you can approximate the original image. I found that I needed to use 8 projections to even begin to get a recognizable image. The following example is generated from 8 projections:
  
 
[[image:targetd_animated.gif]] [[image:target_8_out.png]]  
 
[[image:targetd_animated.gif]] [[image:target_8_out.png]]  

Revision as of 05:30, 5 May 2011

CT Scanning

Some of the techniques used in Tomography were developed by the radiologist Alessandro Vallebona in the 1930's. Vallebona created a technique to overcome the problem of trying to take a clear x-ray image that shows a feature which is lost behind the distracting clutter of foreground and/or background objects. For example, say you wanted to create a cross-section image of the spine. This would be difficult because no matter that angle you take the image from you will get the ribs and internal organs getting in the way of the view. Vallebona's technique was simple and clever. While taking a long exposure he would rotate the x-ray emitter one direction while simultaneously rotating the film in the opposite direction. Anything in the center of rotation would appear still, while objects away from the center of rotation would be blurred away. Special equipment is needed to make sure that the x-ray emitter and the film track smoothly and stay in sync.

If this sounds confusing then imagine you are outside a picket fence that surrounds the house. You can't take a good photo of the house with all the picket slats blocking the view, but if you were looking at the house while sitting in a car driving past the house then the picket slats would blur together and the fence would appear to disappear. To take advantage of this effect with your camera you can't use a fast exposure because that would freeze the slats as if you were not moving. You need a long exposure to blur the fence away, but this would also blur the house; however, if you pivot the camera to track the house while you make the exposure then the wooden slats would still stay blurred, but the house would appear still. A similar trick is used to photograph a race car as it speeds by. Using a high-speed shutter will freeze everything as if there were no motion and you end up with a boring picture of a car sitting in the road with a bunch of people staring at it. But if take the shot with a slow shutter while you track the car speeding past you then the road and the spectators will be a speeding blur, but the car will be in focus.

Back to x-rays...

In a modern Computed Tomography (CT or CaT) system an x-ray emitter and a 1-dimensional detector band is rotated 360 degrees with the target in the middle. The detector band records how much the target attenuates the x-rays at different angles. A series of these snapshot recordings are saved at regular intervals. The series of 1-dimensional bands are used to reconstruct the 2-dimensional plane that intersects a projection of each bands. The number of bands in the series can vary. The more that are recorded, the better the reconstruction. The most common method is called filtered back projection. This is an easy algorithm to implement. Seeing the original reconstructed from a series of projections is rather magical. It seems too easy, but you get what you pay for. Filtered back projection suffers from a number of flaws including artifacts, ambiguous reconstruction shadows, and sensitivity to noise and missing data. No method is perfect, but there are alternatives which are better than filtered back projection. One alternative method is called iterative reconstruction. This method is much more complex and computationally expensive than filtered back projection, but it deals better with noise, incomplete data, and it produces fewer artifacts. There are many algorithms that follow the iterative reconstruction method. One example is Algebraic reconstruction.

In this demo I synthesize a set of 1-dimensional projections of a target image at different angles, then I reconstruct an approximation of the original target image.

Johann Radon defined a transform that for a given target gives a set of 1-dimensional projections of the average of the target's density along lines parallel to a given angle. This transform is called the Radon transform. In our case, the target's "density" is the pixel's brightness. The set of 1-dimensional projections is called a "sinogram", and is graphed along an axis for the angle each 1-dimensional projection.

The Radon transform is related to the CT scanner's recordings of x-ray beam attenuation. In fact, a CT scanner creates a Radom transform of a physical target. One minor distinction to note is that the value of an x-ray beam attenuation through a target is exponential. To make the x-ray recordings equivalent to a Radon transform density projection you would need to take the log of the recorded x-ray values. I use the Radon transform to simulate the set of 1-dimensional projections I might get from a CT scanner. Since I'm generating the Radon transform directly from the image, not using real x-ray recordings, I don't need to take the log of the values.

Johann Radon also showed that if you have a "sinogram" of a target then you can reconstruct an approximation of the original target with an inverse Radon transform. This simply overlays each 1-dimensional projection over each other.

In the following example the 1-dimensional projections of the target are made from only 90 degree rotations of the target image.

Each projection is located at the angle relative to the target from which it was generated.
The target and four
1-dimensional sections.
The position of the
sections corresponds to
the angle of projection relative to the target..
target.png section 4 0.png
section 4 3.png section 4 2.png section 4 1.png

After adding the four 1-dimensional projections together (composite overlay) you get the following CT image:

section 4 0.png+section 4 3.png+section 4 2.png+section 4 1.png = target 4 out.png

As you can see, using only 90 degree projections does not give very good results. The more sections you use the better you can approximate the original image. I found that I needed to use 8 projections to even begin to get a recognizable image. The following example is generated from 8 projections:

targetd animated.gif target 8 out.png

Here is CT image made from 32 radial sections. 32 seems to be a good number for a CT image at this resolution:

target 32 out.png

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.

Shepp-Logan Phantom

Here are the results using the Shepp-Logan Phantom test The Shepp-Logan Phantom is standard test image used in tomography literature to illustrate the quality of reconstruction algorithms. It's the "Lena" test image of the 3D imaging community. I would have chosen Lena Söderberg instead.

A more complex example

target n.png target n out.png target n out enhanced.png

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.

targeto.png targeto out.png


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" />