Morita .Vol import and nhdr conversion - slices out of order

@ChrisMak, see here.

It’s possible the “byte skip” parameter is incorrect.

Also, I can see your data rotated 45° around vertical (I→S) axis.

<tfAntiAliasAngleInDegree value="45"/>

You can use the following Python script to apply transform to align axes:

import numpy as np
from scipy.ndimage import rotate

import read_vol import load_data

path_input = "CT_0.vol"
path_output = "CT_0_rotated.raw"

def main () -> None:
    d = load_data(path_input)

    print("shape before rotation:", d.shape, d.dtype)

    # rotate around last axis (2), relative to center
    d_rot = rotate(d, angle=45, axes=(0, 1), reshape=False, order=1, cval=-32768)
    # flip very first (0) axis
    d_rot = d_rot[::-1, :, :]

    print("shape after rotation:", d_rot.shape)

    with open(path_output, "wb") as f:
        f.write(d_rot.tobytes())

if __name__ == '__main__':
    main()

Then use the following CT_0_rotated.nhdr file:

NRRD0004
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: signed short
dimension: 3
space: left-posterior-superior
sizes: Z Y X
space directions: (0,0,S) (0,S,0) (S,0,0)
kinds: domain domain domain
endian: little
encoding: raw
space origin: (0,0,0)
byte skip: 0
data file: CT_0_rotated.raw

Fill X, Y and Z values from “shape after rotation” script output, S is voxel size.
In your case:

  • X = Y = 240 - (-240) + 1 = 481, Z = 241 - (-242) + 1 = 484
  • S = 0.125
1 Like