niivue / niivue-vscode

NiiVue extension for vscode + standalone web app
https://niivue.github.io/niivue-vscode/
MIT License
21 stars 7 forks source link

Can't load NRRD files with "spacings" in header #50

Closed MattTheCuber closed 5 months ago

MattTheCuber commented 8 months ago

This is a very simple image, when I removed the spacings header, it works perfectly, when I add the spacings header it displays this:

image

Here is a simple example script:

import numpy as np
import nrrd
data = np.random.randint(0, 2, size=(20, 20, 20), dtype=np.uint8)
header = {
    "type": "uint8",
    "dimension": 3,
    "sizes": list(data.shape),
    'encoding': 'gzip',
    "spacings": [1.0, 1.0, 0.625],
}
nrrd.write("data.nrrd", data, header)

Here is the file when I cat it:

> cat data.nrrd
NRRD0005
# This NRRD file was generated by pynrrd
# on 2024-03-08 21:53:01(GMT).
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: uint8
dimension: 3
sizes: 20 20 20
encoding: gzip
spacings: 1 1 0.625

m���0
OD�Ubo����I�Ěg|awr���Jg�S ��M���>~?��+�~���\�|�>���������s!����{���������7=w>�y����<]�9��]���{��ds�wG�q��<y��ϯ��x7p��CM&X��������ʻ��d�:���<�p���L��h���l��#��5h;�=��v�
�X�p��:9e
���v�CR\��v0@Q�D� ����,�"����z"[��9N@DiV^��
Ǒ�a�P�x�x��!�n[�I9�I|�Q��c�h}$:�ߗ�p�Q0G��6�0TG�ĕQ$O���k���A����L�������~����׍(b�=I���5
D�����t��9yz�H��-�V���n=&.C�`4�RsITe��
                                      u�s�m����-@t���M�"�a�*H�]GO�
���&�:��}�S�7�tX8D�YU�&�d�                                        �b�q�H���$Z�����#*�A,�
�I��)΄|d���[]����IPf��@��c�ߝڀ�&���
b�y��(�1r��zJBo�f�1[9A�$�ˬ�R_Zg�"����D��Ԥ�%W���S
�_�m�,�=ZuF����F^�P�M��e�I���[]����=����zX%     �[J�>���jKe7��|<77kd�O�"�.�@a6
S                                                                             )�R"�!c�S�pEV}{v;Aït�gjD�#EJ-�R�r=���     $�9%�OG�xCҢl� nYC7-Yq��Y�j��s��CL�W�د�'*�zFE
4�Q/�`#�_�e�����Z�zޤ�J���ۗu��S�jӎe"9���s1�[�_Β�B�FOD�e&gm<�uOx[^/!8Ä5����M�ח5rlL��@�_�6%K/۠X怡��R����_�X=MC�jb����|��mE����ɬ�肆>�&i��H_��;�3�$C=s,M�e�Tf's���D��f�
 �;K����"�ع�wL��-
                 �WT���2c4���`t*���f;X�p�E�    ��ef�L��e}�n��~ � n��0��ٚ9W�ڡ��'��ݣ<i�pΪ��лMg�'��r{���4l�/�MF�Ԉiq��G6B`91~��4S�.H�~�z��� ����R
                                                                                                                                             ]��n��bA��90���^h��y���t@(
korbinian90 commented 7 months ago

Thank you for posting this!

I could reproduce the failure to open the image, but I couldn't get it to work by removing the spacings header. This is quite weird since it works in the web-version without issues: https://niivue.github.io/niivue-vscode/ Maybe there is a problem with handling compression while reading the file...

MattTheCuber commented 7 months ago

Yeah, I'm not sure. Very strange that the issue didn't resolve when removing the spacings from the header for you...

korbinian90 commented 7 months ago

This issue should be fixed in the new pre-release:

image
MattTheCuber commented 7 months ago

That fixed the issue! Should I close the issue or leave it open until its fully-released?

korbinian90 commented 7 months ago

Let's keep it open for now. I plan to release it soon after some tests (and once I get the release token working again...)

And thanks again for reporting this together with a code example!