Sct_label_vertebrae error: "Images of type float must be between -1 and 1"

Sorry for the second question in as many days, but this is weird and I cant figure out what is going on.

SCT version: dev

I have a spinal cord image, datatype FLOAT32. I segment that cord, I get the _seg nifti, datatype DOUBLE64. I run sct_label vertebrae:

sct_label_vertebrae -i image.nii -s image_seg.nii -c t2

And I get the following error:

Create temporary folder (/var/folders/ff/px4nh9y56fb6kxfmwdks37bc0000gr/T/sct-20190426180711.202626-label_vertebrae-C4AyQs)…

Copying input data to tmp folder…

Create label to identify disc…

Smooth centerline/segmentation…
… Get center of mass of the centerline/segmentation…
… Smoothing algo = hanning
… Windows length = 50
Traceback (most recent call last):
File “/Users/dpapp/sct/scripts/sct_label_vertebrae.py”, line 897, in
main()
File “/Users/dpapp/sct/scripts/sct_label_vertebrae.py”, line 252, in main
im_label_c2c3 = detect_c2c3(im_data, im_seg, contrast)
File “/Users/dpapp/sct/spinalcordtoolbox/vertebrae/detect_c2c3.py”, line 50, in detect_c2c3
nii_im = flatten_sagittal(nii_im, nii_seg, centerline_fitting=‘hanning’, verbose=verbose)
File “/Users/dpapp/sct/scripts/sct_flatten_sagittal.py”, line 73, in flatten_sagittal
img = img_as_float(im_anat_flattened.data[:, :, iz])
File “/Users/dpapp/sct/python/lib/python2.7/site-packages/skimage/util/dtype.py”, line 301, in img_as_float
return convert(image, np.float64, force_copy)
File “/Users/dpapp/sct/python/lib/python2.7/site-packages/skimage/util/dtype.py”, line 205, in convert
raise ValueError(“Images of type float must be between -1 and 1.”)
ValueError: Images of type float must be between -1 and 1.
Sentry is attempting to send 1 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit
Total processing time: 0 min 5 s

Any help would be appreciated

Hi Daniel,
Thank you for reporting this bug. Likely related to a conversion bug we recently fixed in another function.
Could you please let us know what version of SCT you are using, just to make sure we haven’t already fixed it in a more recent version?
Cheers,
Julien

Dear Julien

I was on the development version, downloaded on Jan 29 2019 as per the timestamps.

I switched back to the 4.0.0.beta 2 release, the error has not gone away.

Spinal Cord Toolbox (version: 4.0.0-beta.2)
Running /Users/dpapp/sct_4.0.0-beta.2/scripts/sct_label_vertebrae.py -i sF3T_2013_40_586-154116-00001-00001-1_MTw_OLSfit_TEzero.nii -s sF3T_2013_40_586-154116-00001-00001-1_MTw_OLSfit_TEzero_seg.nii -c t2

Create temporary folder (/var/folders/ff/px4nh9y56fb6kxfmwdks37bc0000gr/T/sct-20190426194033.284022-label_vertebrae-nQoIvr)…

Copying input data to tmp folder…

Straighten spinal cord…
sct_straighten_spinalcord -i data.nii -s segmentation.nii -r 1 # in /private/var/folders/ff/px4nh9y56fb6kxfmwdks37bc0000gr/T/sct-20190426194033.284022-label_vertebrae-nQoIvr

Resample to 0.5mm isotropic…
sct_resample -i data_straight.nii -mm 0.5x0.5x0.5 -x linear -o data_straightr.nii # in /private/var/folders/ff/px4nh9y56fb6kxfmwdks37bc0000gr/T/sct-20190426194033.284022-label_vertebrae-nQoIvr

Apply straightening to segmentation…
isct_antsApplyTransforms -d 3 -i segmentation.nii -r data_straightr.nii -t warp_curve2straight.nii.gz -o segmentation_straight.nii -n Linear # in /private/var/folders/ff/px4nh9y56fb6kxfmwdks37bc0000gr/T/sct-20190426194033.284022-label_vertebrae-nQoIvr
sct_maths -i segmentation_straight.nii -thr 0.5 -o segmentation_straight.nii # in /private/var/folders/ff/px4nh9y56fb6kxfmwdks37bc0000gr/T/sct-20190426194033.284022-label_vertebrae-nQoIvr

Create label to identify disc…
Traceback (most recent call last):
File “/Users/dpapp/sct_4.0.0-beta.2/scripts/sct_label_vertebrae.py”, line 395, in
main()
File “/Users/dpapp/sct_4.0.0-beta.2/scripts/sct_label_vertebrae.py”, line 304, in main
im_label_c2c3 = detect_c2c3(im_data, im_seg, contrast)
File “/Users/dpapp/sct_4.0.0-beta.2/spinalcordtoolbox/vertebrae/detect_c2c3.py”, line 49, in detect_c2c3
nii_im = flatten_sagittal(nii_im, nii_seg,verbose=verbose)
File “/Users/dpapp/sct_4.0.0-beta.2/scripts/sct_flatten_sagittal.py”, line 75, in flatten_sagittal
img = img_as_float(im_anat_flattened.data[:, :, iz])
File “/Users/dpapp/sct_4.0.0-beta.2/python/lib/python2.7/site-packages/skimage/util/dtype.py”, line 301, in img_as_float
return convert(image, np.float64, force_copy)
File “/Users/dpapp/sct_4.0.0-beta.2/python/lib/python2.7/site-packages/skimage/util/dtype.py”, line 205, in convert
raise ValueError(“Images of type float must be between -1 and 1.”)
ValueError: Images of type float must be between -1 and 1.
Sentry is attempting to send 1 pending error messages

Doing the same thing on another set of data produces the same error. I can try reverting back to the stable 3.27 (sic?) release to see if that fixes it.

Daniel

Don’t bother, let me try to reproduce the error on my end, I might ask you to send me an example data if I cannot reproduce.
Thanks!

Daniel,
I cannot reproduce the error (see details here), would you mind sending me the data you used as input?
Thanks,
Julien

I have sent you the data.
I am afraid this might be one of those irreproducible errors I am cursed with. :frowning:

hum… i’m not able to reproduce. I notice the data you sent is called sF3T_2013_40_586-152527-00001-00064-1.nii, and the syntax in this thread uses sF3T_2013_40_586-154116-00001-00001-1_MTw_OLSfit_TEzero.nii. Would you mind sending me the data that produced the error above?
Also, could you please send us the output of sct_check_dependencies?
Thanks!

Dear Julien

In the folder Oxford_error, there should be two subfolders.
In T2, there is a saggital T2 scan. On this scan, i can get the labeling to work without issues. Similarly, on a MEDIC scan, the procedure works.
In MTW, there is the MT weighted scan …_MTw_OLSfit_TEzero.nii, and two segmentations, from deepseg and propseg respectively. Using either of these segmentations, the labeling fails.

Datatypes are as follows:
MTw folder:
…_MTw_OLSfit_TEzero.nii: float32
…_MTw_OLSfit_TEzero_seg_deepseg: double64
…_MTw_OLSfit_TEzero_seg_propseg: double64
T2_sag folder:
sF3T_2013_40_586-152527-00001-00064-1.nii: UINT16
sF3T_2013_40_586-152527-00001-00064-1_seg.nii: double64

For sct_check_dependencies, everything is OK, as is it for sct_testing. See below.

Thank you for your help!
Daniel

SCT info:

  • version: 4.0.0-beta.2

  • path: /Users/dpapp/sct_4.0.0-beta.2

OS: osx (Darwin-18.5.0-x86_64-i386-64bit)

CPU cores: Available: 4, Used by SCT: 4

RAM: Primary memory available: 16.00 gigabytes

Check Python executable…[OK]

Using bundled python 2.7.12 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:43:17)

[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] at /Users/dpapp/sct_4.0.0-beta.2/python/bin/python

Check if data are installed…[OK]

Check if xlwt (1.0.0) is installed…[OK]

Check if xlutils (1.7.1) is installed…[OK]

Check if cryptography (1.6) is installed…[OK]

Check if scikit-learn (0.17.1) is installed…[OK]

Check if scikit-image (0.12.3) is installed…[OK]

Check if pyqt (4.11.4) is installed…[OK]

Check if psutil (5.2.2) is installed…[OK]

Check if matplotlib (1.5.1) is installed…[OK]

Check if pip (9.0.1) is installed…[OK]

Check if requests (2.12.4) is installed…[OK]

Check if xlrd (0.9.4) is installed…[OK]

Check if pandas (0.18.1) is installed…[OK]

Check if dipy (0.11.0) is installed…[OK]

Check if tqdm (4.11.2) is installed…[OK]

Check if nibabel (2.1.0) is installed…[OK]

Check if Keras (2.0.6) is installed…[OK]

Check if futures (3.2.0) is installed…[OK]

Check if pytest-cov (2.5.1) is installed…[OK]

Check if pytest (3.5.0) is installed…[OK]

Check if nipy (0.4.1) is installed…[OK]

Check if h5py (2.7.0) is installed…[OK]

Check if tensorflow (1.3.0) is installed…[OK]

Check if raven (6.2.1) is installed…[OK]

Check if numpy is installed (1.11.2)…[OK]

Check if scipy is installed (0.18.1)…[OK]

Check if spinalcordtoolbox is installed…[OK]

Check ANTs compatibility with OS …[OK]

Check PropSeg compatibility with OS …[OK]

Check if figure can be opened…[OK]

Total processing time: 0 min 16 s

And for sct_testing:

Will run through the following tests:

  • sequentially: sct_deepseg_gm sct_deepseg_lesion sct_deepseg_sc

  • in parallel with 4 jobs: sct_analyze_lesion sct_analyze_texture sct_apply_transfo sct_warp_template sct_resample sct_convert sct_image sct_maths sct_merge_images sct_compute_ernst_angle sct_compute_hausdorff_distance sct_compute_mtr sct_compute_mscc sct_compute_snr sct_concat_transfo sct_create_mask sct_crop_image sct_dice_coefficient sct_detect_pmj sct_dmri_compute_dti sct_dmri_concat_bvals sct_dmri_concat_bvecs sct_dmri_create_noisemask sct_dmri_compute_bvalue sct_dmri_moco sct_dmri_separate_b0_and_dwi sct_dmri_transpose_bvecs sct_extract_metric sct_flatten_sagittal sct_fmri_compute_tsnr sct_fmri_moco sct_get_centerline sct_label_utils sct_process_segmentation sct_propseg sct_register_multimodal sct_straighten_spinalcord sct_register_to_template sct_segment_graymatter sct_smooth_spinalcord sct_label_vertebrae

Checking sct_deepseg_gm…[OK]

Checking sct_deepseg_lesion…[OK]

Checking sct_deepseg_sc…[OK]

Checking sct_analyze_lesion…[OK]

Checking sct_analyze_texture…[OK]

Checking sct_apply_transfo…[OK]

Checking sct_warp_template…[OK]

Checking sct_resample…[OK]

Checking sct_convert…[OK]

Checking sct_image…[OK]

Checking sct_maths…[OK]

Checking sct_merge_images…[OK]

Checking sct_compute_ernst_angle…[OK]

Checking sct_compute_hausdorff_distance…[OK]

Checking sct_compute_mtr…[OK]

Checking sct_compute_mscc…[OK]

Checking sct_compute_snr…[OK]

Checking sct_concat_transfo…[OK]

Checking sct_create_mask…[OK]

Checking sct_crop_image…[OK]

Checking sct_dice_coefficient…[OK]

Checking sct_detect_pmj…[OK]

Checking sct_dmri_compute_dti…[OK]

Checking sct_dmri_concat_bvals…[OK]

Checking sct_dmri_concat_bvecs…[OK]

Checking sct_dmri_create_noisemask…[OK]

Checking sct_dmri_compute_bvalue…[OK]

Checking sct_dmri_moco…[OK]

Checking sct_dmri_separate_b0_and_dwi…[OK]

Checking sct_dmri_transpose_bvecs…[OK]

Checking sct_extract_metric…[OK]

Checking sct_flatten_sagittal…[OK]

Checking sct_fmri_compute_tsnr…[OK]

Checking sct_fmri_moco…[OK]

Checking sct_get_centerline…[OK]

Checking sct_label_utils…[OK]

Checking sct_process_segmentation…[OK]

Checking sct_propseg…[OK]

Checking sct_register_multimodal…[OK]

Checking sct_straighten_spinalcord…[OK]

Checking sct_register_to_template…[OK]

Checking sct_segment_graymatter…[OK]

Checking sct_smooth_spinalcord…[OK]

Checking sct_label_vertebrae…[OK]

status: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Finished! Elapsed time: 274s

Total processing time: 4 min 35 s

Ah! sorry about that, i just picked the first folder… OK, good news: I can reproduce the error. And another good news: it is fixed in a branch we will soon be merging to master. Stay tuned :slight_smile:

Please note: while the error is fixed in this branch (which you can already test, by the way), I would not advise to run vertebral labeling on datasets with low resolution along the SI direction because: (i) the discs are poorly resolved and (ii) the straightening procedure applied on thick axial slices introduces interpolation errors which you probably want to avoid.

The general workflow, is that vertebral labeling is ran on an isotropic resolution dataset (e.g., the T2w data you also have), and then labeling is transferred to other data acquired during the same session, assuming subject did not move along the SI direction (usually a fair assumption). If you don’t want to assume that, then i suggest you use sct_label_utils -create-viewer to manually label your discs for each subject.

Cheers,
Julien