nipy / nibabel

Python package to access a cacophony of neuro-imaging file formats
http://nipy.org/nibabel/
Other
654 stars 258 forks source link

nibabel plugin for napari? #978

Closed grlee77 closed 3 years ago

grlee77 commented 3 years ago

Is there interest in having a plugin for napari that would allow reading the formats supported by nibabel?

I created a basic one a few months back that can read most image formats supported by nibabel (I did not implement DICOM). I don't expect to personally be able to spend much time developing it further in the near term, but would be happy to make this prototype available. An essential features that is currently missing is properly using the orientation info, but it is a start. I can upload to a personal repo, but thought I would check in first here and see if there was interested in keeping this under the nipy org instead.

On the napari side, there is not yet an orthogonal viewer mode as in FSLeyes, etc, but such a mode is planned for the future: napari/napari#1478

effigies commented 3 years ago

Cool, I hadn't heard of napari. Thanks for the pointer! If they prefer remotely-managed plugins instead of a gallery they control, I think nipy would be a good place to host it.

grlee77 commented 3 years ago

Cool, I hadn't heard of napari. Thanks for the pointer!

I think the primary creators are from a microscopy background, so that has been their initial focus. It is nice that any additional dimensions beyond three spatial dimensions gets its own slider, so you can easily have 4d or 5d data with sliders for time, contrast, magnitude/phase, etc.

Aside from visualization, it is possible to have it perform computations interactively as demonstrated recently for deconvolution of 3D microscopy data in this blog post created by some people at NVIDIA: https://blog.dask.org/2020/11/12/deconvolution

If they prefer remotely-managed plugins instead of a gallery they control, I think nipy would be a good place to host it.

I have not asked the napari team about this. @jni, do you know what the napari team's preferred approach is?

jni commented 3 years ago

@jni, do you know what the napari team's preferred approach is?

Yeah, we definitely want a distributed approach to this!

responsibility

We'd absolutely love to see a nibabel plugin! In fact I used one of the nibabel example datasets in my SciPy Japan talk on napari! Please use the Framework :: napari trove classifier so that we can autodiscover the plugin on PyPI!

grlee77 commented 3 years ago

Sounds like it would be best to host it here, then. If someone can create a napari-nibabel repository for me to upload what I have so far, that would be great.

We can mark the repo as experimental in the README and wait until it is a little more mature before putting anything up on PyPI.

effigies commented 3 years ago

@grlee77 I've invited you as an organization owner and you can set things up how you like. (If you'd rather not be, let me know and I can set up the repo.)

grlee77 commented 3 years ago

Great, I have now created a repository. The following formats can be opened: NIFTI1, NIFTI2, ANALYZE, Philips PAR/REC, MINC1, MINC2, AFNI BRIK/HEAD and MGH/MGZ

Here is a screenshot of a volume rendering of some PAR/REC phantom data that is used by nibabel's tests: napari_phantom

If we get the affine and voxel dimension support added, this would be much better, though. The axial, sagittal and coronal 2D slices in that same repo all display at the same orientation since it currently just loads the raw data matrix without considering the orientation.

arokem commented 3 years ago

This is cool! And has a lot of potential. Would you mind posting the code you wrote to produce that image?

On Thu, Dec 10, 2020 at 8:21 PM Gregory R. Lee notifications@github.com wrote:

Great, I have now created a repository https://github.com/nipy/napari-nibabel. The following formats can be opened: NIFTI1, NIFTI2, ANALYZE, Philips PAR/REC, MINC1, MINC2, AFNI BRIK/HEAD and MGH/MGZ

Here is a screenshot of a volume rendering of some PAR/REC phantom data https://github.com/grlee77/parrec_oblique/tree/master/NIFTI that is used by nibabel's tests: [image: napari_phantom] https://user-images.githubusercontent.com/6528957/101861570-58dfb880-3b3e-11eb-8552-b7c76b7f178b.png

If we get the affine and voxel dimension support added, this would be much better, though. The axial, sagittal and coronal 2D slices in that same repo all display at the same orientation since it currently just loads the raw data matrix without considering the orientation.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nipy/nibabel/issues/978#issuecomment-742959047, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA46NVOE5X7RJWKWDFUIYDSUGM6BANCNFSM4UUCIAGQ .

grlee77 commented 3 years ago

If you have napari, you can install the plugin from the repo (it is not yet on PyPI)

pip install git+https://github.com/nipy/napari-nibabel

I then just called napari 3D_T1W_trans_35_25_15_SENSE_26_1.nii in a terminal to open the image file in the GUI. In the GUI it starts out in a 2D view, but if you click on the 2D vs. 3D icon (2nd from bottom left), it will switch to a 3D view. Then it is just setting the rendering to "iso" and adjust the "iso threshold" slider as needed to get the image above.

I am sure this can also be done from a script, but I am new to napari and wouldn't know the commands offhand.

grlee77 commented 3 years ago

Also the entirety of the plugin is in this one, short file so it should be pretty simple to modify going forward: https://github.com/nipy/napari-nibabel/blob/main/napari_nibabel/nibabel.py

I also added some basic tests which currently rely on specific paths within nibabel. If those are likely to remain stable over time then we can keep it that way and avoid keeping duplicate copies of the test files in the plugin repo. They are pretty small, though, so it wouldn't be a big problem to store a copy there as well.

arokem commented 3 years ago

Yep. That works!

Screen Shot 2020-12-10 at 8 59 15 PM
jni commented 3 years ago

I then just called napari 3D_T1W_trans_35_25_15_SENSE_26_1.nii in a terminal to open the image file in the GUI. In the GUI it starts out in a 2D view, but if you click on the 2D vs. 3D icon (2nd from bottom left), it will switch to a 3D view. Then it is just setting the rendering to "iso" and adjust the "iso threshold" slider as needed to get the image above.

I am sure this can also be done from a script, but I am new to napari and wouldn't know the commands offhand.

For future stumblers-upon-this-issue, this should work (more or less, not checked for typos):

import napari

filename = '3D_T1W_trans_35_25_15_SENSE_26_1.nii'

with napari.gui_qt():
    v = napari.Viewer(ndisplay=3)  # open in 3D mode straight away
    layer = v.open(filename)[0]  # returns a list of layers
    layer.rendering = 'iso'
jni commented 3 years ago

Thanks @grlee77 for getting this started, it's super exciting!

effigies commented 3 years ago

Closing this, since it exists. Happy to add a link in the docs if there's a good place to advertise.