Skip to content

Commit

Permalink
Make sct_get_centerline robust to intensities ∈ [0, 1] (#1746)
Browse files Browse the repository at this point in the history
* add a intensity scaling prior to int16 conversion to prevent intensity < 1

* Add refs in the header of the functions

* add ref optic deepseg_sc

* convert to uint16

* for intensities between 0 and 1 the data was not rescaled, we removed the "if" condition

* use changeType

* the if condition is crucial for binary images as input.

* use skimage.img_as_uint + be robust to negative values with an intensity translation

* img_as_int instead of img_as_uint

* replace the skimage functions --> rescale in uint16 range then convert to uint16


Former-commit-id: dea98c9
  • Loading branch information
charleygros authored and jcohenadad committed May 22, 2018
1 parent dd00660 commit a66cc16
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -147,6 +147,8 @@ alt="Fsleyes integration" width="240" height="180" border="10" /></a>
- [De Leener et al. Automatic segmentation of the spinal cord and spinal canal coupled with vertebral labeling. IEEE Transactions on Medical Imaging 2015](https://www.ncbi.nlm.nih.gov/pubmed/26011879)
- [Dupont SM, De Leener B, Taso M, Le Troter A, Stikov N, Callot V, Cohen-Adad J. Fully-integrated framework for the segmentation and registration of the spinal cord white and gray matter. Neuroimage 2017](https://www.ncbi.nlm.nih.gov/pubmed/27663988)
- [Perone et al. Spinal cord gray matter segmentation using deep dilated convolutions. Sci Rep 2018](https://www.nature.com/articles/s41598-018-24304-3)
- [Gros et al. Automatic segmentation of the spinal cord and intramedullary multiple sclerosis lesions with convolutional neural networks](https://arxiv.org/pdf/1805.06349.pdf)
- [Gros et al. Automatic spinal cord localization, robust to MRI contrasts using global curve optimization. MIA 2017](https://www.sciencedirect.com/science/article/pii/S136184151730186X)

#### Registration
- [Cohen-Adad et al. Slice-by-slice regularized registration for spinal cord MRI: SliceReg. Proc ISMRM 2015](https://www.dropbox.com/s/v3bb3etbq4gb1l1/cohenadad_ismrm15_slicereg.pdf?dl=0)
Expand Down
3 changes: 2 additions & 1 deletion scripts/msct_image.py
Expand Up @@ -386,7 +386,8 @@ def changeType(self, type=''):
min_out = iinfo(type).min
max_out = iinfo(type).max
# before rescaling, check if there would be an intensity overflow
if (min_in < min_out) or (max_in > max_out):

if (min_in < min_out) or (max_in > max_out): # This condition is important for binary images since we do not want to scale them
sct.printv('WARNING: To avoid intensity overflow due to convertion to '+type+', intensity will be rescaled to the maximum quantization scale.', 1, 'warning')
# rescale intensity
data_rescaled = self.data * (max_out - min_out) / (max_in - min_in)
Expand Down
2 changes: 1 addition & 1 deletion scripts/sct_deepseg_sc.py
Expand Up @@ -32,7 +32,7 @@
def get_parser():
# Initialize the parser
parser = Parser(__file__)
parser.usage.set_description("""Spinal Cord Segmentation using deep convolutional networks.""")
parser.usage.set_description("""Spinal Cord Segmentation using convolutional networks. \n\nReference: C Gros, B De Leener, et al. Automatic segmentation of the spinal cord and intramedullary multiple sclerosis lesions with convolutional neural networks (2018). arxiv.org/abs/1805.06349""")

parser.add_option(name="-i",
type_value="image_nifti",
Expand Down
2 changes: 1 addition & 1 deletion scripts/sct_get_centerline.py
Expand Up @@ -45,7 +45,7 @@ def viewer_centerline(image_fname, interslice_gap, verbose):
def get_parser():
# Initialize the parser
parser = Parser(__file__)
parser.usage.set_description("""This function allows the extraction of the spinal cord centerline. Two methods are available: OptiC (automatic) and Viewer (manual).""")
parser.usage.set_description("""This function allows the extraction of the spinal cord centerline. Two methods are available: OptiC (automatic) and Viewer (manual).\n\nReference: C Gros, B De Leener, et al. Automatic spinal cord localization, robust to MRI contrasts using global curve optimization (2017). doi.org/10.1016/j.media.2017.12.001""")

parser.add_option(name="-i",
type_value="image_nifti",
Expand Down
17 changes: 16 additions & 1 deletion spinalcordtoolbox/centerline/optic.py
Expand Up @@ -92,7 +92,22 @@ def detect_centerline(image_fname, contrast_type,

# convert image data type to int16, as required by opencv (backend in OptiC)
image_int_filename = sct.add_suffix(file_data + ext_data, "_int16")
sct_image.main(args=['-i', image_fname, '-type', 'int16', '-o', image_int_filename, '-v', '0'])
img = Image(image_fname)
img_int16 = img.copy()

# rescale intensity
min_out = np.iinfo('uint16').min
max_out = np.iinfo('uint16').max
min_in = np.nanmin(img.data)
max_in = np.nanmax(img.data)
data_rescaled = img.data * (max_out - min_out) / (max_in - min_in)
img_int16.data = data_rescaled - (data_rescaled.min() - min_out)

# change data type
img_int16.changeType('uint16')
img_int16.setFileName(image_int_filename)
img_int16.save()
del img, img_int16

# reorient the input image to RPI + convert to .nii
reoriented_image_filename = sct.add_suffix(image_int_filename, "_RPI")
Expand Down

0 comments on commit a66cc16

Please sign in to comment.