Author: Marta Nuñez-Garcia (marnugar@gmail.com)
Implementation of the method described in: Automatic multiplanar CT reformatting from trans-axial into left ventricle short-axis view. Marta Nuñez-Garcia et al. STACOM (2020). Please cite this reference when using this code. PDF available here: hal.inria.fr. Also in this repo (SAX_reformat_Stacom2020_cr.pdf)
Given a raw trans-axial (TA) CT image and the corresponding LV endo, LV wall and RV epi segmentations (.mha or .vtk), compute LV short axis view image. It also reformats the masks.
Get meshes from masks and use them to find the transformation that aligns:
- MV plane
- Septum (RV position with regard to LV position)
- LV long axis to the corresponding theoretical planes in standard short-axis view. Manually set image parameters in the beginning: image size (nb of voxels), spacing, keep_physical_location = True/Fals
Resampling diagram:
Schematic pipeline:
With respect to the method presented in the paper, this code additionally includes:
- a 4th rotation (suggested and implemented by Nicolas Cedilnik) that improves LV septum alignment: after a preliminary reformat to sax, use LV endo and LV epi masks (a slice midway along the long axis) to compute LV and RV centers and get the rotation matrix that will place the RV to the left of the LV.
- The option of keeping the image world coordinates so they match in TA and SAX (default is TRUE).
- The option of performing an initial automatic check of complete LV in TA view. If check_lv_cropped = True, exit if not complete (cropped) LV.
- Automatic check of potential appex cropping with current spacing and spacing modification if necessary.
A couple of additional functionalities are also included:
- Basic Quality Control (QC) of the result: check final LV long axis direction (on a slightly different mesh) and compare it to the theoretical, expected, one.
- 17-AHA LV wall parcellation computation (compute_17_aha_segments_LVwall.py). The division is done according to the "official" definition, notably, taking into account that "only slices containing myocardium in all 360° are included", i.e. part of the base is excluded.
- 17 regions LV mesh parcellation computation (compute_17_segments_mesh.py). Given a LV wall segmentation and corresponding mesh (endo, epi, midwall etc) compute 17-AHA segmentation projecting the division on the LV wall image to the mesh. Additionally compute alternative parcellation directly on the mesh (17 regions but not 17-AHA since this one fully includes the basal region).
A few reformatted images may show problems when displayed by some tools (i.e. ITK-SNAP error message: Failed to load image (...). Image has an invalid orientation (code XYZ)). In those cases, images can be displayed using 3D Slicer, for instance, ticking the option "Ignore Orientation". Still the XYZ axes may be displayed in an odd manner (views can appear flipped). The orientation can be manually set to an easier-to-display one by using the code in workaround_visualization_issue.py but, importantly, the matching world coordinates with initial TA image will be lost (not relevant in most situations...). Not sure if it is worthy to by default apply the workaround to all cases since this issue does not happen very often.
Clone the repository:
git clone https://github.com/martanunez/SAX_reformatting_public
[Optional] Create specific conda environment:
conda create --name sax_reformatting python=3.9
conda activate sax_reformatting
Install required packages (see Dependencies section below):
cd SAX_reformatting_public
python setup.py install
[Optional] Manually install required packages, e.g.:
conda install -c simpleitk simpleitk
conda install -c anaconda numpy
pip install vtk # conda not good behaviour
pip install pyvista
pip install pyacvd
The scripts in this repository were successfully run with:
python main.py [-h] [--path PATH] [--ct_im FILENAME]
[--mask_lvendo FILENAME] [--mask_lvwall FILENAME] [--mask_rvepi FILENAME]
[--save SAVE] [--isotropic ISO]
Arguments:
-h, --help Show this help message and exit
--path Path to folder with input data
--ct_im Input CT image name
--mask_lvendo Input LV endo mask name
--mask_lvwall Input LV wall mask name
--mask_rvepi Input RV epi mask name
--save Save intermediate results (rotated meshes etc.)
--isotropic If output must be isotropic
python main.py --path example_pat0/ --ct_im ct.mha --mask_lvendo ct-lvendo.mha --mask_lvwall ct-lvwall.mha --mask_rvepi ct-rvepi.mha
Usage example 2: reformat image to short-axis view + compute corresponding 17-AHA segments + get epicardial mesh and parcellate it (17-AHA and 17 regions including full basal part)(elapsed time: 64 s)
python main.py --path example_pat0/ --ct_im ct.mha --mask_lvendo ct-lvendo.mha --mask_lvwall ct-lvwall.mha --mask_rvepi ct-rvepi.mha
python reformat_masks_to_SAX.py --path example_pat0/ --ct_im_sax ct-sax.mha --R_filename ct-R-matrix-sax.txt --mask_lvendo ct-lvendo.mha --mask_lvwall ct-lvwall.mha --mask_rvepi ct-rvepi.mha --mask_lvepi ct-lvepi-sax.mha
python compute_17_aha_segments_LVwall.py --path example_pat0/ --mask_lvendo_sax ct-lvendo-sax.mha --mask_lvwall_sax ct-lvwall-sax.mha --mask_rvepi_sax ct-rvepi-sax.mha --mask_lvepi_sax ct-lvepi-sax.mha
python compute_17_segments_mesh.py --path example_pat0/ --ct_mask ct-lvepi-sax.mha --ct_lvwall_labels_mask ct-lvwall-sax-dil-aha.mha
The code in this repository is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details: http://www.gnu.org/licenses/

