MIC-DKFZ / niicat

This is a tool to quickly preview nifti images on the terminal
GNU General Public License v2.0
51 stars 10 forks source link

UnboundLocalError: local variable 'oL' referenced before assignment #3

Closed fepegar closed 3 years ago

fepegar commented 4 years ago
$ niicat t1.nii.gz                                                                                                        ✓  29% (0:52) 🔋  00:42:40
Traceback (most recent call last):
  File "/Users/fernando/miniconda3/envs/episurg/bin/niicat", line 50, in <module>
    main()
  File "/Users/fernando/miniconda3/envs/episurg/bin/niicat", line 46, in main
    plot(args.nifti_file, dpi=args.dpi)
  File "/Users/fernando/miniconda3/envs/episurg/lib/python3.6/site-packages/niicat/plotter.py", line 248, in plot
    return _plot_nifti_preview(iFile, return_fig=return_fig, dpi=dpi)
  File "/Users/fernando/miniconda3/envs/episurg/lib/python3.6/site-packages/niicat/plotter.py", line 159, in _plot_nifti_preview
    plt.text(-10, mY + 5, oL, fontsize=9, color='red')  # Label on left side
UnboundLocalError: local variable 'oL' referenced before assignment

You might want to check nibabel docs for some high-level utilities to get image orientation.

fepegar commented 4 years ago

Orientation info from image header:

In [5]: nii.get_qform()
Out[5]:
array([[  0.        ,   0.        ,   1.        , -82.6807251 ],
       [ -1.        ,   0.        ,   0.        , 132.33735657],
       [  0.        ,  -1.        ,   0.        , 102.21686554],
       [  0.        ,   0.        ,   0.        ,   1.        ]])

In [6]: nii.get_sform()
Out[6]:
array([[ -0.        ,   0.        ,   1.        , -82.6807251 ],
       [ -1.        ,  -0.        ,  -0.        , 132.33735657],
       [  0.        ,  -1.        ,   0.        , 102.21686554],
       [  0.        ,   0.        ,   0.        ,   1.        ]])
wasserth commented 4 years ago

nib.aff2axcodes(image.affine) gives different results unfortunately. But I updated the code. Now this error should not occur anymore.