-
Notifications
You must be signed in to change notification settings - Fork 51
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
I am not able to read a nrrd file saved from Slicer (volume sequence) #71
Comments
Will need to look at this later. Can you provide a copy of the NRRD file that is causing problems? |
I think it's already telling us that there is a duplicate header field. @jcnils |
Thank you for the reply @addisonElliott , I asked the lab for the anonymized data or one volume sequence with the phantom. But I got the same problem with the dataset from 3D Slicer. @tashrifbillah I could not find a way to edit the header on the 3D Slicer natively, and I still need a way to load the binaries in an array before writing it back. I will try to do it using the simpleitk.io
|
@tashrifbillah I managed to read it using simpleitk, then write it as you told. I was able to open the new file with pynrrd. I noticed that simpleitk and 3d slicer deal with the sequence as being components instead of an x+1 array, in this case a 3D data with 26 components. When I export it to a numpy array it becomes a 4D array instead, and can be written/read by pynrrd. But I cannot open it as a sequence on the 3D slicer again, instead I get a really weird image.
|
Alright, finally got some time to take a look at this. I was able to get your NRRD file loaded without using SimpleITK. There are two ways to do this. Method 1The first way is to edit the NRRD file manually to remove the duplicate fields. Not sure how familiar you are with the NRRD file format, but the headers is just text at the beginning of the file. Thus, you can open the NRRD file with your text editor and remove the additional space line. Here is what the header of the CTP-cardio-seg.nrrd looks like:
The duplicate line is the space field at the very bottom. If you remove that line and try again, it works fine. Method 2If you want to ignore any duplicate field errors like I mentioned, then there is some code to do this. The snippet of code I gave you earlier was wrong and doesn't work. Here is what does work:
Note: In your snippet, you use r to prefix the string. This is used for regex strings. Not necessary for a normal string. With that in mind, you're welcome to keep using SimpleITK but it takes a few more lines that what is required for pynrrd. In addition, I'm not sure if saving the NRRD file will cause issues with loading it in 3D Slicer again. I have loaded .seg.nrrd files and saved them before using pynrrd and I was able to load it back into 3D Slicer. |
@ihnorton @tashrifbillah I don't understand why but Slicer sometimes adds duplicate fields to NRRD files. For new users who just want to load in their NRRD, I think it can be difficult to know to use the ALLOW_DUPLICATE_FIELD switch. What do you think about the following?
|
@jcnils what version of Slicer are you using? I think I fixed the duplicate field issue in the last few months (but I didn't try with sequences). |
@addisonElliott documentation and a suggestion in the duplicate field error would be helpful, for people using software versions with this issue. |
@ihnorton We are using the 4.8.1 in the lab, accordingly to our supervisor there are some modules and libraries not working with the 4.11, in my case I am also using the dtcwt library but the 4.11 didn't install it properly using the pip. I will post the difficulties we are facing about the last version on slicer forum. It will be ideal to use the newer versions. this example do not work on slicer 4.11:
I tried to save the sequence with the 4.11 and it works, no duplicated header. Thank you very much. |
@addisonElliott Thank you ! Both methods are working perfectly. I managed to open it back on slicer by also writing the header. I am using this documentation https://media.readthedocs.org/pdf/pynrrd/latest/pynrrd.pdf, it is very useful.
Thank you very much, devs on the lab will be very pleased, since we decided to change file formats to .nrrd people are looking for some reliable way to get the arrays, and this library is perfect for it. |
Going to leave this open as a reminder to document and add code example for ALLOW_DUPLICATE_FIELD. Will try and get the PR going this weekend, unless @jcnils is up for the task. |
Of course. |
Documentation update to include the ALLOW_DUPLICATE_FIELD information (#71 ) Create docstring for ALLOW_DUPLICATE_FIELD and compile it into the API reference page. Includes example of how to use field and information on the getting started page about its purpose. Fix small issue with ALLOW_DUPLICATE_FIELD test that referenced by wrong name. Also updated the API reference to show the ALLOW_DUPLICATE_FIELD docstring in addition to it being displayed in the table of contents for the reading section. Update references to True/False & ALLOW_DUPLICATE_FIELD so Sphinx appropriately links to these items. Also found a small mistake in the tests that was missed originally I decided to fix here. Wasn't worth the extra effort of a separate PR.
To read the nrrd volume works perfectly if I save it as single volume using Slicer, but if I save it as volume sequence I find the following errors:
File "...\nrrd\reader.py", line 209, in read_header
header = read_header(fh, custom_field_map)
File "...\nrrd\reader.py", line 261, in read_header
raise NRRDError(dup_message)
nrrd.errors.NRRDError: Duplicate header field: 'space'
filedata = nrrd.read_data(VOL0)
File "...\nrrd\reader.py", line 313, in read_data
raise NRRDError('Header is missing required field: "%s".' % field)
nrrd.errors.NRRDError: Header is missing required field: "dimension".
When I realized that the problem is with sequences, I thought sequences are not the focus of the library, but I am opening this just in case.
Thanks
The text was updated successfully, but these errors were encountered: