Giter Club home page Giter Club logo

niicat's Introduction

niicat

This is a tool to quickly preview nifti images on the terminal. This can be helpful if you are working on a remote server via SSH and do not have a -X connection. It uses libsixel to display the images. Niicat can also display png, jpg or similar images.

Install:

pip install niicat

Usage:

niicat T1.nii.gz

Possible problems

If nothing is displayed check if your terminal supports sixel.

Per default niicat is trying to use libsixel-python. If this is causing problems you can also try using niicat with the option -ic if you are using iterm2 (this will use imgcat from iterm2) or with the option -lb (this will use libsixel-bin which can be installed via sudo apt install libsixel-bin).

Niicat was only tested on python >= 3.5.

Copyright

Copyright © German Cancer Research Center (DKFZ), Division of Medical Image Computing (MIC). Please make sure that your usage of this code is in compliance with the code license.

niicat's People

Contributors

sophmrtn avatar wasserth avatar yarikoptic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

niicat's Issues

AttributeError: type object 'Path' has no attribute 'home'

I've pip3 installed niicat on my Ubuntu 18 machine, but I am having trouble running it.

$ niicat t1.nii.gz 
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/niicat/resources/niipre.py", line 17, in <module>
    home = str(Path.home())
AttributeError: type object 'Path' has no attribute 'home'

I am using

$ python3 --version
Python 3.6.8

Cool project!

UnboundLocalError: local variable 'oL' referenced before assignment

$ 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.

`libsixel-python` is missing.

$ niicat icbm_avg_152_t1_tal_nlin_symmetric_VI.nii.gz 
`libsixel-python` is missing. See https://github.com/saitoha/libsixel

$ pip install libsixel-python    
Requirement already satisfied: libsixel-python in /Users/fernando/miniconda3/envs/episurg/lib/python3.6/site-packages (0.5.0)

$ niicat icbm_avg_152_t1_tal_nlin_symmetric_VI.nii.gz 
`libsixel-python` is missing. See https://github.com/saitoha/libsixel

$ ipython                  
Python 3.6.7 | packaged by conda-forge | (default, Jul  2 2019, 02:07:37)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.6.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import libsixel
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-7b2ccdc20b41> in <module>
----> 1 import libsixel

~/miniconda3/envs/episurg/lib/python3.6/site-packages/libsixel/__init__.py in <module>
    350
    351 if not find_library('sixel'):
--> 352     raise ImportError("libsixel not found.")
    353
    354 # load shared library

ImportError: libsixel not found.

name 'libsixel' is not defined

I have started work on making your software automatically accessible on Gentoo Linux. However there seems to be an issue with the installation:

chymera@darkhost ~ $ niicat /usr/share/mouse-brain-atlases/dsurqec_200micron.nii 
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.6/niicat", line 34, in <module>
    main()
  File "/usr/lib/python-exec/python3.6/niicat", line 30, in main
    plot_preview(args.nifti_file)
  File "/usr/lib64/python3.6/site-packages/niicat/niipre.py", line 222, in plot_preview
    plot_sixel(fig)
  File "/usr/lib64/python3.6/site-packages/niicat/niipre.py", line 26, in plot_sixel
    if not libsixel:
NameError: name 'libsixel' is not defined

This is surprising, because the libsixel package is installed, providing the following files:

darkhost ~ # equery f media-libs/libsixel
 * Searching for libsixel in media-libs ...
 * Contents of media-libs/libsixel-1.8.2:
/usr
/usr/bin
/usr/bin/img2sixel
/usr/bin/libsixel-config
/usr/bin/sixel2png
/usr/include
/usr/include/sixel.h
/usr/lib64
/usr/lib64/libsixel.so -> libsixel.so.1.0.6
/usr/lib64/libsixel.so.1 -> libsixel.so.1.0.6
/usr/lib64/libsixel.so.1.0.6
/usr/lib64/pkgconfig
/usr/lib64/pkgconfig/libsixel.pc
/usr/share
/usr/share/bash-completion
/usr/share/bash-completion/completions
/usr/share/bash-completion/completions/img2sixel
/usr/share/doc
/usr/share/doc/libsixel-1.8.2
/usr/share/doc/libsixel-1.8.2/ChangeLog.bz2
/usr/share/doc/libsixel-1.8.2/NEWS.bz2
/usr/share/doc/libsixel-1.8.2/README.md.bz2
/usr/share/doc/libsixel-1.8.2/images
/usr/share/doc/libsixel-1.8.2/images/egret.jpg
/usr/share/doc/libsixel-1.8.2/images/map16.png
/usr/share/doc/libsixel-1.8.2/images/map8.png
/usr/share/doc/libsixel-1.8.2/images/snake.jpg
/usr/share/doc/libsixel-1.8.2/images/vimperator3.png
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/img2sixel.1.bz2
/usr/share/man/man1/sixel2png.1.bz2
/usr/share/man/man5
/usr/share/man/man5/sixel.5.bz2
/usr/share/zsh
/usr/share/zsh/site-functions
/usr/share/zsh/site-functions/_img2sixel

Any idea what's going wrong?

be able to specify coords for cross-cut

ATM there is no way to adjust AFAIK

$> niicat --help
usage: niicat [-h] [-ic] [-lb] [--dpi N] [--version] nifti_file

Generate previews of nifti image and png/jpeg images on the terminal.

positional arguments:
  nifti_file

optional arguments:
  -h, --help  show this help message and exit
  -ic         Use iTerm2's imgcat instead of libsixel-python to plot the image.
  -lb         Use libsixel-bin instead of libsixel-python to plot the image.
  --dpi N     resolution for plotting (default: 150).
  --version   show program's version number and exit

AttributeError: 'FigureCanvasGTK3Agg' object has no attribute 'renderer'

I get the following error when trying to run niicat — any ideas what could be wrong?

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.7/niicat", line 50, in <module>
    main()
  File "/usr/lib/python-exec/python3.7/niicat", line 46, in main
    plot(args.nifti_file, dpi=args.dpi)
  File "/usr/lib/python3.7/site-packages/niicat/plotter.py", line 254, in plot
    return _plot_nifti_preview(iFile, return_fig=return_fig, dpi=dpi)
  File "/usr/lib/python3.7/site-packages/niicat/plotter.py", line 233, in _plot_nifti_preview
    _plot_sixel(fig)
  File "/usr/lib/python3.7/site-packages/niicat/plotter.py", line 36, in _plot_sixel
    res = _sixel_encode(fig.canvas.buffer_rgba(), fig.get_figwidth()* dpi, fig.get_figheight() * dpi)
  File "/usr/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 444, in buffer_rgba
    return self.renderer.buffer_rgba()
AttributeError: 'FigureCanvasGTK3Agg' object has no attribute 'renderer'

My matplotlib installation has gtk3 support enabled (though the error remains the same with it disabled):

[U] dev-python/matplotlib
     Available versions:  3.2.2-r2^t (~)3.3.0-r1^t (~)3.3.1-r2^t {cairo doc examples excel gtk3 latex qt5 test tk wxwidgets PYTHON_TARGETS="python3_6 python3_7 python3_8 python3_9"}
     Installed versions:  3.2.2-r2^t(03:19:33 PM 09/18/2020)(cairo gtk3 latex wxwidgets -doc -examples -excel -qt5 -test -tk PYTHON_TARGETS="python3_7 -python3_6 -python3_8 -python3_9")
     Homepage:            https://matplotlib.org/
     Description:         Pure python plotting library with matlab like syntax

error in plotter: `ctypes.ArgumentError: argument 2: TypeError: wrong type`

I get the following error when trying to run niicat on a nifti file:

Traceback (most recent call last):
  File "/raid/shared/tbartczak/conda/envs/tb/bin/niicat", line 50, in <module>
    main()
  File "/raid/shared/tbartczak/conda/envs/tb/bin/niicat", line 46, in main
    plot(args.nifti_file, dpi=args.dpi)
  File "/raid/shared/tbartczak/conda/envs/tb/lib/python3.11/site-packages/niicat/plotter.py", line 254, in plot
    return _plot_nifti_preview(iFile, return_fig=return_fig, dpi=dpi)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/raid/shared/tbartczak/conda/envs/tb/lib/python3.11/site-packages/niicat/plotter.py", line 233, in _plot_nifti_preview
    _plot_sixel(fig)
  File "/raid/shared/tbartczak/conda/envs/tb/lib/python3.11/site-packages/niicat/plotter.py", line 36, in _plot_sixel
    res = _sixel_encode(fig.canvas.buffer_rgba(), fig.get_figwidth()* dpi, fig.get_figheight() * dpi)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/raid/shared/tbartczak/conda/envs/tb/lib/python3.11/site-packages/niicat/plotter.py", line 23, in _sixel_encode
    libsixel.sixel_dither_initialize(dither, data, w, h, libsixel.SIXEL_PIXELFORMAT_RGBA8888)
  File "/raid/shared/tbartczak/conda/envs/tb/lib/python3.11/site-packages/libsixel/__init__.py", line 503, in sixel_dither_initialize
    status = _sixel.sixel_dither_initialize(dither, data, width, height, pixelformat,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ctypes.ArgumentError: argument 2: TypeError: wrong type

I've installed niicat from source from the version in #8 as I got nibabel issues with pypi version.

From the stacktracie it seems that wrong datatype is passed to sixel when encoding figure?

My env:
Python 3.11
matplotlib==3.7.1
matplotlib-inline==0.1.6
numpy==1.24.3
nibabel==5.1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.