math
math

Reputation: 8820

How do I determine the endianness of a NifTi file?

I've a NifTi file and when I load it values are strangely scattered within scope of int_32. However, when I load the same file via NifTi-Python bindings, the value-range is different and correct. (I know that this is correct, as the producer of the file (FSL), claims only to produce values within that range.) So I want to check if the values are really stored in a different endianness (compared to other files), and if so, interpret those values correctly then.

Upvotes: 4

Views: 770

Answers (1)

Adriano Repetti
Adriano Repetti

Reputation: 67090

You can use the first field in the nifti_1_header structure. It's sizeof_hdr and it contains the size of the header (in my case a single 348 bytes structure rather than three smaller structs).

Simply read first 4 bytes of the header, it should be 348 (alias 0x0000015C), if it has been written in big endian you'll have 0x5C010000 (so on disk you'll read 5C 01 00 00 for little endian and 00 00 01 5C for big endian).

Upvotes: 4

Related Questions