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

passing a header dict to the write method #37

Closed
d13g0 opened this issue Mar 31, 2018 · 8 comments
Closed

passing a header dict to the write method #37

d13g0 opened this issue Mar 31, 2018 · 8 comments
Assignees

Comments

@d13g0
Copy link

d13g0 commented Mar 31, 2018

It would be very useful to be able to pass a complete header dictionary to the write method. For instnace if you read a NRRD file, then do operations on the header and then you want to save the same data with the updated header.
One of such operations is to add metadata like indicated here:
http://teem.sourceforge.net/nrrd/lib.html#keyvalue

Another operation is to save the data in a different coordinate system. In that case it would be ideal to be able to update the respective fields in the header and then write the data with the new header.

@addisonElliott
Copy link
Collaborator

Can you elaborate on what you mean by this?

In nrrd.write, you are able to pass in an options dictionary that will be written to the NRRD file. However, the limitation is that pynrrd only writes approved keys to the file. So custom keys such as look-at or camera would be ignored. Is this what you mean?

If so, another example is with 3D Slicer when writing segmentation NRRD files. There are quite a few specific parameters that are written to the NRRD file that should ideally be preserved to allow loading back into 3D Slicer at a later point.

@d13g0
Copy link
Author

d13g0 commented Apr 5, 2018 via email

@addisonElliott
Copy link
Collaborator

addisonElliott commented Apr 5, 2018

If I'm understanding you correctly, what you are describing is possible in NRRD.

You can load in a NRRD file, change the type from int to float, and save it and it will work. You can also change any of the parameters in the metadata and then save it.

Let me give you an example.

import nrrd

filename = NRRD_FILE_HERE
volume, options = nrrd.read(filename);

# Change volume to float type, this will be reflected in new NRRD file written
volume = volume.astype(float);

# Change space origins option in dictionary, should be reflected in new NRRD file written
options['space origin'] = ['200.0', '-100.0', '100.0']

nrrd.write(filenameNew, volume, options);

Note: There are some limitations such that space origin should be a list of strings instead of a list of integers. I am planning on fixing this soon and submitting pull request.

Also, you make a good point that documentation is nice to have.

@addisonElliott
Copy link
Collaborator

@d13g0 Did this solve your problem? Is there anything else you needed help with, in regard to pynrrd?

@addisonElliott
Copy link
Collaborator

Bump again. I'm assuming you've solved your issue, can you close this then please?

@d13g0
Copy link
Author

d13g0 commented Apr 27, 2018 via email

@addisonElliott
Copy link
Collaborator

addisonElliott commented Apr 27, 2018

So when you say 'custom' metadata, I am taking it as it is not one of the fields mentioned here: https://github.com/mhe/pynrrd/blob/master/nrrd.py#L117

You are correct that is a limitation of this library. It is on my (long) TODO list to get to. It would be nice to be able to load custom fields and then write them back.

Probably worthwhile to keep this issue open until it is resolved. Thanks for clarifying!

@addisonElliott addisonElliott self-assigned this Jun 18, 2018
@addisonElliott
Copy link
Collaborator

Fixed in #57

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

No branches or pull requests

2 participants