"**Author:** David D. W. Johansen | **Email:** s214743@dtu.dk"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### **CT padding pipeline**\n",
"This notebook provides a pipeline for reconstruction using the padding method to mitigate the ROI problem, which can lead to circle and cupping artifacts. An ordinary reconstruction is first done to see whether such artifacts are present and for comparison later in the notebook. There is also export functionality at the end."
"# TIGRE is faster on large-scale CT according to https://tomopedia.github.io/software/tigre/\n",
"from cil.recon import FDK # Uses TIGRE\n",
"\n",
"from cil.processors import Slicer\n",
"\n",
"from cil.utilities.jupyter import islicer\n",
"from cil.utilities.display import show2D"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"import viz_utils"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<module 'viz_utils' from '/dtu/3d-imaging-center/projects/2024_QIM_platform/analysis/3dim-reconstruction/viz_utils.py'>"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import importlib\n",
"import sys\n",
"importlib.reload(sys.modules['viz_utils'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### **User parameters**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All the parameters required for the pipeline are set here in the beginning of the notebook. They are also mentioned where they are used. Here they are described in detail:\n",
"\n",
"- `ct_path`: the path to the CT reconstruction metadata file. Should be from **Nikon** (`.xtekct`) or **ZEISS** (`.txrm`).\n",
"\n",
"- `center_height`: determines how many center-most slices to use from the projections. Setting it to `'full'` uses the whole projection volume. `center_height` cannot exceed the height of the projections.\n",
"\n",
"- `pad_factor`: the amount of padding to add at each side of the sinogram in the padding method. Thus setting `pad_factor = 0.25` will make the sinogram 50% bigger. From previous experiments `pad_factor` should be set to at least `0.25` to make the method work properly (pushing the artifacts outside of the ROI). There might be benefits from choosing an even higher `pad_factor`, but this is a case-by-case basis and depends on the specific dataset.\n",
"\n",
"- `save_to_disk`: boolean variable for toggling saving the padded reconstruction. **If `save_to_disk` is set to `True`, then an existing file may be overwritten.**\n",
"\n",
"- `clip_range`: the intensity range that will be used to clip the volume when exporting.\n",
"\n",
"- `base_filename`: the base filename will be used for exporting. The file is saved under the HDF5 format and the extension `.h5` will be appended."
"For faster processing, we may work on a subset of slices. `center_height` determines how many of the center-most slices should be used. Set to `'full'` to use full volume."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def create_reader(file_name, roi=None):\n",
" # Wrapper for \n",
" if file_name.endswith('txrm'):\n",
" DataReader = ZEISSDataReader\n",
" elif file_name.endswith('xtekct'):\n",
" DataReader = NikonDataReader\n",
" else:\n",
" raise ValueError(\"Unrecognizable CT metadata file. File extension should either be '.txrm' or '.xtekct'\")\n",
"In the following, the padded data is passed as a sinogram to FDK, while the original image geometry is used for the volume to reconstruct. This is more efficient than the default behaviour of reconstructing on a correspondingly padded volume that we would have to crop to the original size anyway."
"The parameter `vrange` specifies the ranges to use. Not specifying it or setting it to `None` uses each of the volumes full intensity range. Experimenting with `vrange` can be used to finetune `clip_range`."
"Choose the interval `clip_range` to clip the data to and the `base_filename` to save to (the extension is added automatically). The `clip_range` and `pad_factor` will be stored as metadata. The reconstruction volume will be converted to uint16 for exporting."
**Author:** David D. W. Johansen | **Email:** s214743@dtu.dk
%% Cell type:markdown id: tags:
### **CT padding pipeline**
This notebook provides a pipeline for reconstruction using the padding method to mitigate the ROI problem, which can lead to circle and cupping artifacts. An ordinary reconstruction is first done to see whether such artifacts are present and for comparison later in the notebook. There is also export functionality at the end.
%% Cell type:markdown id: tags:
### **Python module imports**
%% Cell type:code id: tags:
```
import glob, os, pathlib
import psutil
import qim3d
import cil
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import clear_output
from ipywidgets import interact, interactive, IntSlider
import math
import h5py
```
%% Cell type:code id: tags:
```
from cil.io import ZEISSDataReader, NikonDataReader
from cil.utilities.display import show_geometry, show2D
from cil.processors import TransmissionAbsorptionConverter
# TIGRE is faster on large-scale CT according to https://tomopedia.github.io/software/tigre/
from cil.recon import FDK # Uses TIGRE
from cil.processors import Slicer
from cil.utilities.jupyter import islicer
from cil.utilities.display import show2D
```
%% Cell type:code id: tags:
```
import viz_utils
```
%% Cell type:code id: tags:
```
import importlib
import sys
importlib.reload(sys.modules['viz_utils'])
```
%% Output
<module 'viz_utils' from '/dtu/3d-imaging-center/projects/2024_QIM_platform/analysis/3dim-reconstruction/viz_utils.py'>
%% Cell type:markdown id: tags:
### **User parameters**
%% Cell type:markdown id: tags:
All the parameters required for the pipeline are set here in the beginning of the notebook. They are also mentioned where they are used. Here they are described in detail:
-`ct_path`: the path to the CT reconstruction metadata file. Should be from **Nikon** (`.xtekct`) or **ZEISS** (`.txrm`).
-`center_height`: determines how many center-most slices to use from the projections. Setting it to `'full'` uses the whole projection volume. `center_height` cannot exceed the height of the projections.
-`pad_factor`: the amount of padding to add at each side of the sinogram in the padding method. Thus setting `pad_factor = 0.25` will make the sinogram 50% bigger. From previous experiments `pad_factor` should be set to at least `0.25` to make the method work properly (pushing the artifacts outside of the ROI). There might be benefits from choosing an even higher `pad_factor`, but this is a case-by-case basis and depends on the specific dataset.
-`save_to_disk`: boolean variable for toggling saving the padded reconstruction. **If `save_to_disk` is set to `True`, then an existing file may be overwritten.**
-`clip_range`: the intensity range that will be used to clip the volume when exporting.
-`base_filename`: the base filename will be used for exporting. The file is saved under the HDF5 format and the extension `.h5` will be appended.
For faster processing, we may work on a subset of slices. `center_height` determines how many of the center-most slices should be used. Set to `'full'` to use full volume.
%% Cell type:code id: tags:
```
def create_reader(file_name, roi=None):
# Wrapper for
if file_name.endswith('txrm'):
DataReader = ZEISSDataReader
elif file_name.endswith('xtekct'):
DataReader = NikonDataReader
else:
raise ValueError("Unrecognizable CT metadata file. File extension should either be '.txrm' or '.xtekct'")
In the following, the padded data is passed as a sinogram to FDK, while the original image geometry is used for the volume to reconstruct. This is more efficient than the default behaviour of reconstructing on a correspondingly padded volume that we would have to crop to the original size anyway.
The parameter `vrange` specifies the ranges to use. Not specifying it or setting it to `None` uses each of the volumes full intensity range. Experimenting with `vrange` can be used to finetune `clip_range`.
Choose the interval `clip_range` to clip the data to and the `base_filename` to save to (the extension is added automatically). The `clip_range` and `pad_factor` will be stored as metadata. The reconstruction volume will be converted to uint16 for exporting.