Message Boards Message Boards

3 Replies
3 Total Likes
View groups...
Share this post:

Does Mathematica support Nearly Raw Raster Data NRRD file fomat?

Posted 11 years ago
I am willing to use M's image processing APIs on some MRI scans from which makes available information in NRRD file format. But I don't see this extension in file formats supported by Mathematica. Is it possible to convert nrrd to some format that Mathematica can work with ?
POSTED BY: Pankaj Sejwal
3 Replies
Posted 11 years ago
Also, it's possible to write custom import and export converters that work directly with Import and Export commands. If you want to go to this depth, see and .
POSTED BY: Jari Kirma

I see your scans from Insight are 2-byte signed integer voxels encoded (within the NRRD file) with GZIP.  I'm guessing you just want to get to the raster datacube, and don't care about all the interpolation and sampling management stuff that the NRRD Library provides ( 

One possible option, that I didn't try because I don't feel like building the "unu" command line utility ( from source code, is to use unu to convert your NRRD files to VTK format  ( which Mathematica does import (see Help on Import).  But "unu" conversion support is incomplete, and I don't know how completely M supports VTK. 

The other is to take an NRRD file from Insight, then use a hex editor to chop out its header, (chop right before the "1f 8b" gzip hex lead-in) then save-as .gzip.  Then use 7-Zip to extract  the .gzip file into a binary file.  From here, I can read and display in M, as so:
SetDirectory[ <to wherever your file resides>]
grab = BinaryReadList["5074-004-01_10_t2_fit.nrrd", "Integer16", ByteOrdering -> 1]; 
        // This ByteOrdering worked on my Windows PC.  Either 1 or -1
192*256*256  // The results of these two lines should agree!
slices= Partition[Partition[grab, 256], 256];
Image[slices[[64]], "Bit16"]  // Should immediately display an image slice.
   Since Mathematica itself can decode GZIP, the entire process should be able to be able to be automated within M, i.e. no need to externally use a hex editor and GZIP.   If you can't take it from here, let me know, and if I'm not too busy, I'll finish a set of Mathematica commands to automate everything (that is, ignoring generality; only specifically handling these 5 files). 
POSTED BY: Frank Iannarilli
Posted 11 years ago
@Frank Iannarilli : I am very thankful to you for this suggestion as it worked for me. I was able to generate slices though initially I faced problem because I had to rename my extracted file as *.nrrd and than only M was able to get it.
Your offer to spend time on helping me automate was very kind.

POSTED BY: Pankaj Sejwal
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract