Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader update #5

Open
Chris-N-K opened this issue Mar 31, 2021 · 10 comments
Open

Reader update #5

Chris-N-K opened this issue Mar 31, 2021 · 10 comments
Labels
enhancement New feature or request

Comments

@Chris-N-K
Copy link

Hi,

I have a question regarding the dimension order the reader uses. Wouldn't it be convenient if we change the axis order to the order napari uses (reader at the moment: t,x,y,z vs napari: t,z,y,x). This way the image gets displayed in a more natural way.

I use to flip the y axis to display the patients back at the bottom, as the reading direction of this dimension differ between my files and napari. Is this a general problem or just specific for my files?

Best Regards
Christopher

@Chris-N-K Chris-N-K added the enhancement New feature or request label Apr 15, 2021
@grlee77
Copy link
Contributor

grlee77 commented Apr 15, 2021

This seems fine. Given that we don't have an official release here yet, I am not too worried about breaking backwards compatibility

In general, we need to incorporate the affine orientation information from the headers to make sure things are oriented correctly. As I am sure you are aware, left vs. right is hard to visually distinguish for brains, so some care is needed to make sure it is correct!

@Chris-N-K
Copy link
Author

Chris-N-K commented Apr 16, 2021

In the images I mainly use I can clearly identify the left and right side. As of now left right was always displayed correctly. Only top and bottom were always inverted. Did this happen for your images?

As of now napari supports affine transformations. I already tested an implementation. Sadly if given an affine matrix the scale parameter is no longer used and my flip of top and bottom does no longer work.

@Chris-N-K
Copy link
Author

Chris-N-K commented Apr 19, 2021

As mentioned in the writer thread it will be beneficial to switch from storing the header and affine matrix in napari.viewer.layer.metadata to storing the image object. We should not lose any functionality and the memory demand should not be much different I think.

@Chris-N-K
Copy link
Author

@effigies I try to find a robust method to get the reading directions for each dimension from the image header. I hope to find a solution working with each image format.

I want to do this to stop displaying the nifti files upside down in napari.

@effigies
Copy link
Member

Could you clarify what you mean? What is the format of a "reading direction"? We may already have something like what you need in https://github.com/nipy/nibabel/blob/master/nibabel/orientations.py, but in any event, it should not be difficult to calculate it from the affine.

@Chris-N-K
Copy link
Author

Chris-N-K commented Apr 26, 2021

The reading direction of each array dimension in a nifti file is documented in the qform and sform if I'm right. (Sanner, unknown, etc.) I don't realy know if the other formats have a similar information in their header. I would like to include a function to detect this reading direction to always display the images in the right orientation. In general I try to make napari directional aware like FSL or other medical viewers.

I hope I could explain it in a clearer way now.

Edit:
I found what I need in the module you mentioned. Sry for not looking thoroughly enough through nibabel. Now I'm only strugling with the transformation of the affine matrix to changed dimension order (from xyz(t) to (t)zyx). I suppose there is probably a function somewhere too.

@effigies
Copy link
Member

The affine matrix doesn't encode any information about the temporal dimension. Almost all formats have their spatial axes first, with MINC being the primary exception. We have a function for determining this: nibabel.imageclasses.spatial_axes_first (code).

@Chris-N-K
Copy link
Author

Chris-N-K commented Apr 26, 2021

I know that the affine matrix does not include temporal information. To use affine transformation in napari with 4D images I extend the matrix to 5x5. That works fine by the way.

I would like to display anterior to posterior in the z axis after loading into napari. To achieve this I need to shift the axis order from xyz to zyx. But if I do this the affine matrix does no longer fit. To shift the translation part of the matrix is no problem but with the 3x3 scale / rotate / sheer matrix part I hit my limits. I thought to transpose the matrix would do the trick but I suppose I was naive. Everything I tried did not lead to a correctly transformed image.

@Chris-N-K
Copy link
Author

I uploaded an updated version of the reader to a new branch. It follows the discussed script name convention and supports image orientation. The original image object is now stored in the metadata.

Affine transformation is not included as napari can not correctly display the 2D views if non-orthogonal slicing is needed.

@Chris-N-K
Copy link
Author

@effigies the affine matrix always casts the image to the RAS orientation right?
I try to calculate the affine matrix that casts to SPL, but simply do not get how to do it...
Could you give me a hand?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants