Skip to main content

View brain images in terminal using ASCII characters

Project description

ascnii

If you always wanted to plot NIfTI images in terminal using ASCII characters, you can do so now using the command line tool ascnii.

However, for now, ascnii assumes that the image is in MNI space, and will likely not work for other kinds of inputs (at the moment)!

Set up:

You can simply install from PyPI:

pip install ascnii

You may or may not want to set up a virtual environment.

python3 -m venv .examplevenv
source .examplevenv/bin/activate
pip install -U pip

Alternatively, you can install from github. Clone the repository to where you would like to install it.

git clone https://github.com/LeSasse/ascnii.git
cd ascnii
pip install -e .

How to use:

Run ascnii --help:

usage: ascnii [-h] [-o OUTPUT] [-H] [-C COLUMNS] [-c] [-m COLORMAP]
              [-b {black,red,red,green,yellow,blue,magenta,cyan,white}]
              [-t THRESHOLD] [-cc CUT_COORDS CUT_COORDS CUT_COORDS] [-a] [-d]
              nifti

View NIfTI images in terminal using ASCII characters.

positional arguments:
  nifti                 Path to the NIfTI file.

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        How to output the brain image. By default, prints to
                        {'terminal'}. Otherwise, accepts a path to a html file or a
                        txt file.
  -H, --header          If activated, print out the image header as well.
  -C COLUMNS, --columns COLUMNS
                        Number of character columns (in terminal) to use for
                        plotting.
  -c, --colorbar        If activated, a colorbar is plotted with the brain images.
  -m COLORMAP, --colormap COLORMAP
                        Choose a colormap for the image.
  -b {black,red,red,green,yellow,blue,magenta,cyan,white}, --background {black,red,red,green,yellow,blue,magenta,cyan,white}
                        Choose a terminal color for the background.
  -t THRESHOLD, --threshold THRESHOLD
                        Threshold the given image below this value.
  -cc CUT_COORDS CUT_COORDS CUT_COORDS, --cut_coords CUT_COORDS CUT_COORDS CUT_COORDS
                        MNI coordinates at which to plot the image.
  -a, --annotate        If activated, positions and left/right annotation are
                        added.
  -d, --draw_cross      If activated, a cross is drawn on the plot to indicate the
                        cut position.

Examples:

Simple default plot of an anatomical image (3D) on a small terminal window:

ascnii example_img.nii.gz:

plot

You can also plot 4D NIfTI images, ascnii will simply plot the mean image.

Adjust the resolution with the --columns option:

By default, ascnii will use the complete width of the terminal, but you may want to adjust width manually. Make sure to zoom out a bit, so your terminal has enough space and run ascnii example_img.nii.gz --columns 600:

plot

This is also useful if you want to output the ASCII image as an html to achieve higher resolution. For example ascnii example_img.nii.gz --columns 700 -o example_html.html results in the image here.

Change colormap and background color:

In order to change the colormap choose any of the matplotlib colormaps and hand them over as strings to the --colormap option. At the same time you can also change the background color by handing any of the values listed for the --background option. Run ascnii example_img.nii.gz -m plasma -b white:

plot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ascnii-0.0.1.dev21.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

ascnii-0.0.1.dev21-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file ascnii-0.0.1.dev21.tar.gz.

File metadata

  • Download URL: ascnii-0.0.1.dev21.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for ascnii-0.0.1.dev21.tar.gz
Algorithm Hash digest
SHA256 2c08f6ba02fa4b703730188bda046482094752598aca5e2f0d04e7c375e0b505
MD5 3d7807f05a0f56429e3043781d930fc3
BLAKE2b-256 841ec1e17281529bf6fe2adba7aa5e497ab73d70e28a6d8a44839430351f539b

See more details on using hashes here.

File details

Details for the file ascnii-0.0.1.dev21-py3-none-any.whl.

File metadata

  • Download URL: ascnii-0.0.1.dev21-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for ascnii-0.0.1.dev21-py3-none-any.whl
Algorithm Hash digest
SHA256 d506874a3950436ee06d2c2afc0d84ae198006eeb611e469dd1164795b095224
MD5 926affc74f9b17cc7faa2faf978e27e6
BLAKE2b-256 35689ff323574c3df1fedab69a520480ccd7c9637cf5a5b35920100b2fa04abb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page