ofgulban / segmentator

3D MRI data exploration and segmentation tool.
https://github.com/ofgulban/segmentator/wiki
BSD 3-Clause "New" or "Revised" License
74 stars 13 forks source link

Cannot reopen nii file created be Segmentator #88

Closed bakerhassan closed 4 years ago

bakerhassan commented 4 years ago

I edited an nii MRI file and then I exported it using Export nifti button, then I tried to open the saved file using Segmentator but it gives the following error:

Default GUI is selected.
Input image data type is float32.
/usr/local/lib/python3.7/site-packages/segmentator-1.6.0-py3.7-macosx-10.14-x86_64.egg/segmentator/utils.py:150: RuntimeWarning: divide by zero encountered in true_divide
/usr/local/lib/python3.7/site-packages/segmentator-1.6.0-py3.7-macosx-10.14-x86_64.egg/segmentator/utils.py:150: RuntimeWarning: invalid value encountered in multiply
Scharr gradient method is selected.
  Computing gradients...
  Gradient magnitude computed in: 0 seconds.
Preparing GUI...
/usr/local/lib/python3.7/site-packages/numpy/lib/nanfunctions.py:1371: RuntimeWarning: All-NaN slice encountered
  overwrite_input=overwrite_input, interpolation=interpolation
Traceback (most recent call last):
  File "/usr/local/bin/segmentator", line 11, in <module>
    load_entry_point('segmentator==1.6.0', 'console_scripts', 'segmentator')()
  File "/usr/local/lib/python3.7/site-packages/segmentator-1.6.0-py3.7-macosx-10.14-x86_64.egg/segmentator/__main__.py", line 173, in main
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "/usr/local/lib/python3.7/site-packages/segmentator-1.6.0-py3.7-macosx-10.14-x86_64.egg/segmentator/segmentator_main.py", line 52, in <module>
  File "/usr/local/lib/python3.7/site-packages/segmentator-1.6.0-py3.7-macosx-10.14-x86_64.egg/segmentator/utils.py", line 201, in prep_2D_hist
ValueError: cannot convert float NaN to integer

I also tried to gunzip the resulted file but also didn't work out.

ofgulban commented 4 years ago

Hi @bakerhassan ,

Thanks for opening this issue and reporting the problem nicely. The Export Nifti button saves a binary nifti image *_label_0.nii.gz. So I have 2 points about this:

  1. You would not want to open this binary nifti image (a.k.a mask, a.k.a *_label_0.nii.gz) in Segmentator because it only consists of zeros and ones.
  2. I am guessing that you want to open your original nifti file after masking it with the binary nifti image saved by Segmentator. In this case:
    1. You can apply this mask by using -for example- fslmaths command of FSL: fslmaths /path/to/image.nii.gz -mas /path/to/image_label_0.nii.gz /path/to/image_masked.nii.gz
    2. Then you open the masked image with Segmentator again: segmentator /path/to/image_masked.nii.gz

Let me know whether this is helpful or not.

bakerhassan commented 4 years ago

Yes, that was helpful! Thanks