dfsp-spirit / freesurferformats

GNU R package for reading and writing neuroimaging file formats. Not limited to FreeSurfer anymore, despite its name.
Other
23 stars 3 forks source link

[Feature request] Add `vox2ras_tkr` to mgh/mgz reader's headers #18

Closed dipterix closed 4 years ago

dipterix commented 4 years ago

Freesurfer has vox2ras-tkr matrix, which has the same Mdc matrix as vox2ras_matrix but different location/center.

For example, I can read in mgz file with headers

res <- freesurferformats::read.fs.mgh(path, with_header = TRUE,
                                        flatten = FALSE, drop_empty_dims = FALSE)

Norig matrix (i.e. vox2ras_matrix)

# res$header$internal$M, or
res$header$vox2ras_matrix

>      [,1] [,2] [,3]      [,4]
> [1,]   -1    0    0 127.88193
> [2,]    0    0    1 -98.06789
> [3,]    0   -1    0 116.37625
> [4,]    0    0    0   1.00000

Torig matrix which is vox2ras-tkr

Mdc <- res$header$internal$Mdc
Pcrs_c <- res$header$internal$Pcrs_c
rbind(cbind(Mdc, - Mdc %*% Pcrs_c), c(0,0,0,1))

>      [,1] [,2] [,3] [,4]
> [1,]   -1    0    0  128
> [2,]    0    0    1 -128
> [3,]    0   -1    0  128
> [4,]    0    0    0    1

Reference: https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems

dfsp-spirit commented 4 years ago

I think the function freesurferformats::mghheader.vox2ras.tkreg() already computes this from the header, but I'm on mobile right now, will need to verify later.

Or is it important to you that it exists as a field in the header structure?

dipterix commented 4 years ago

I see. Thanks I didn't realize there was a function to calculate that. This is good enough.