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

Converting multi-component image to nii #59

Open
adityaapte opened this issue Jun 20, 2023 · 4 comments
Open

Converting multi-component image to nii #59

adityaapte opened this issue Jun 20, 2023 · 4 comments

Comments

@adityaapte
Copy link

I would like to write deformation vector field (dx,dy,dz volumes) as a multi-component image. Any suggestions on how to organize the input image and other metadata as an input to set_nii_hdr.m and nii_tool.m?

@xiangruili
Copy link
Owner

I am not clear about your purpose. Are you trying to store something like FSL warping file?

@adityaapte
Copy link
Author

The requirement is to have 3 components per pixel - component 1: x-deformation. component 2: y-deformation and component 3: z-deformation. I was able to make progress by converting the DVF matrix to 8-D image as specified in help doc. The next issue is that the image pixel values get converted to uint8. Is there a setting to specify retaining the pixel intensities as float.
% Another way to signify RGB/RGBA data is to permute color dim to 8th-dim of img
% (RGB_dim of 8 can be omitted then). Since NIfTI img can have up to 7 dim,
% nii_tool chooses to store RGB/RGBA in 8th dim. Although this looks lengthy
% (4th to 7th dim are often all ones), nii_tool can deal with up to 7 dim
% without causing any confusion. This is why the returned nii.img always stores
% RGB in 8th dim.

@xiangruili
Copy link
Owner

xiangruili commented Jun 20, 2023

I am not sure, but it sounds like you are not dealing with RGB images, so don't put that into 8th dim.

You can simply use the 4th dim to store the x/y/z-deformation component, as FSL warping files do. Although NIfTI specification reserves 4th-dim for time, but no one cares or follows it.

I suppose the metadata will be same as or similar to whatever NIfTI you derive the deformation vectors from.

@adityaapte
Copy link
Author

adityaapte commented Jun 20, 2023

When I save x/y/z deformation in the 4th dimension, the image written to nii is 4-D. It has 16-element direction cosines (instead of 9 element). Also, NumberOfComponentsPerPixel=1 instead of 3. Perhaps I am missing the metadata required to tell the nii writer to treat the 4th dimension of the image as 3 components per pixel instead of a separate dimension.

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