I’d like to know how can I get the relationship between pixels and mm from Matlab, as I know it has to be somewhere because with the Slicer Ruler tool, it’s possible to measure structures in mm.
It is defined in img.ijkToLpsTransform as a 4x4 homogeneous transformation matrix. From nrrdread.m:
img.ijkToLpsTransform: pixel (IJK) to physical (LPS, assuming 'space' is 'left-posterior-superior')
coordinate system transformation, the origin of the IJK coordinate system is (1,1,1) to match Matlab matrix indexing
Note that this matrix include origin, spacing, and axis directions of the volume.
You can convert a coordinate from IJK (voxel) to LPS (physical, in mm) coordinate system by multiplying the coordinate by ijkToLpsTransform from the left. Spacing is the norm of column vectors of ijkToLpsTransform.
Using the valuable information provided, I tried to measure the distance in mm between two points with matlab, but I think I’m doing something wrong:
Assuming that M = cli_imageread(inputParams.inputvolume);
And Point1 and Point2 are the coordinates of two different points from M which are in the same slice, I’ve used the next code but I must have misunderstood something:
Don’t compute spacing. Use the matrix to convert point coordinates from IJK to LPS coordinate system. Unit of LPS coordinate system is mm, so distance that you compute in LPS is the distance you need. Something like this: