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

Fix zero length matrix transpose #34

Closed
wants to merge 1 commit into from
Closed

Conversation

nx10
Copy link
Contributor

@nx10 nx10 commented Nov 5, 2022

Transpose was broken for zero length 2D matrices. T([]) now returns [] instead of throwing an exception.

This fixes #30 ... partially. It can now open the files without crashing and displays (as far as I can see) the correct dimensions. But the images themselves do not seem to be displayed properly.

Here is an example file to replicate this

(Source: C-PAC_Derivatives\preproc\output\cpac_cpac_preproc\sub-0025429_ses-1\anat\sub-0025429_ses-1_from-template_to-T1w_mode-image_desc-nonlinear_xfm.nii.gz from https://osf.io/syqvc/ with permission. Thanks @gkiar !)

vscode-neuro-viewer:

image

Other viewers (i.e. MRIcroGL):

image

@anibalsolon
Copy link
Owner

Hi @nx10 Thank you for the PR!
It is a fine solution, however it does no tackle the origin of the problem, but only masks it.

With your help, looking at the points in which your change in the transpose function have impact, I was able to understand better the problem and create a fix for it. It is regarding affine matrices, that transform the image space. I use it to compute the direction of the data, using its eigenvalues. The issue is regarding when the affine is all zero, eignv are also zero and my code falls apart. Now, if an affine matrix is all zero, it will just return the orientation vector as [1,1,1].

I will close this PR and reference you in my commit as co-author.

@nx10
Copy link
Contributor Author

nx10 commented Nov 10, 2022

@anibalsolon great news! And thank you for looking further into this.

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

Successfully merging this pull request may close these issues.

Some .nii.gz won't open, even though they open fine on other viewers
2 participants