anibalsolon / vscode-neuro-viewer

Check metadata and visualize neuroimages within VSCode.
https://marketplace.visualstudio.com/items?itemName=anibalsolon.neuro-viewer
MIT License
43 stars 6 forks source link

Fix zero length matrix transpose #34

Closed nx10 closed 2 years ago

nx10 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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