Building the ijk to RAS transform from a nrrd file

Almost correct. IJKToRAS is a homogeneous transformation matrix, which contains axis directions in the top-left 3x3 sub-matrix, origin in the first 3 values of 4th column, and [0,0,0,1] in the 4th row (so you don’t “add” the translation component but concatenate). In Matlab syntax:

ijk_to_lps = [[space_directions, space_origin]; [0 0 0 1]]
lps_to_ras = diag([-1 -1 1 1])
ijk_to_ras = lps_to_ras * ijk_to_lps