NIFTI-Reader-JS icon indicating copy to clipboard operation
NIFTI-Reader-JS copied to clipboard

How to change the Orientation of Nifti Image and show it to canvas

Open ai-watcher opened this issue 1 year ago • 1 comments

I load the nifti-1 file using nifti-reader-js and get the header of the nifti. Now i am trying to change the orientation of the image like RAS to LAS or LPS and show it to canvas. How to do it after reading the file header?

ai-watcher avatar Aug 23 '24 08:08 ai-watcher

@ai-watcher I would recommend looking into Niivue for rendering nifti images. Niivue uses nifti-reader-js under the hood. However, images are always displayed in the Niivue canvas using RAS for consistency across all the applications that the Niivue library is used in.

hanayik avatar Aug 23 '24 08:08 hanayik

I am closing this issue, as it is out of for NIFTIReader-JS, as this question is about image processing, not image reading. As @hanayik notes, you can either use NiiVue or extract NiiVue's code (as it uses a permissive license). The relevant NiiVue function is conform which emulates the FreeSurfer python conform function and is very similar to the nibabel python conform. The NiiVue conform live demo allows you to drag and drop your own NIfTI images, conform them and save the results. Note hat conform not only swizzles the row, column, slice order of NIfTI images to RAS (or the FreeSurfer default of LIA), but it also reslices to a new grid. If you simply want to swizzle spatial order of rows, columns and slices losslessly, you may want to look at how NiiVue works out the permutations for the orthogonal 48 combinations. The one caveat with the NiiVue implementation is that the re-orientation of voxel data is done on the massively parallel GPU using a GLSL shader, so you will have to write JavaScript code for the swizzling (the conform shows how). Both methods also show how the NIfTI sform is updated to show the correct orientation and origin.

neurolabusc avatar Feb 16 '25 12:02 neurolabusc