BRAINSia / BRAINSTools

A suite of tools for medical image processing focused on brain analysis
http://brainsia.github.io/BRAINSTools/
Apache License 2.0
111 stars 96 forks source link

NrrdToFSL: DWIConvert vs ConvertBetweenFileFormats #342

Open reckbo opened 7 years ago

reckbo commented 7 years ago

Description

Given an LPS DWI nrrd, DWIConvert makes an LAS nifti, and given a single diffusion volume of that nrrd, ConvertBetweenFileFormats makes an LPS nifti. This has consequences when converting back to nrrd, namely the j in ijk space is flipped in the first case, but remains unchanged and matches the original in the latter case. (The world coordinates are fine and correct).

Issue

Here's an example of where this affected me:

  1. LPS DWI nrrd -> DWIConvert -> LAS nifti -> bet -> ConvertBetweenFileFormats -> LPS DWI mask with j axis flipped
  2. LPS DWI nrrd -> extract baseline -> ConvertBetweenFileFormats -> LPS nifti -> bet -> ConvertBetweenFileformats -> LPS DWI mask with original ijk orientation

Usually I mask a nrrd using unu 3op ifelse but that does so in ijk space, so 1 does not work, but 2 is fine. So my questions are:

  1. Is there a reason for this discrepancy in behaviour?
  2. Is there a way to mask in world coordinate space?

Reproduce

git clone https://github.com/pnlbwh/BRAINSTools-debug cd BRAINSTools-debug && make

hjmjohnson commented 7 years ago

ConvertBetweenFileFormats attempts to maintain the input images direction cosines as closely as possible.

DWIConvert tries to match the FSL standards. Due to the fact that the BVEC and BVAL information is implicitly in an LAS corrdinate system (and the fact that the measurement frame is implicitly an identity matrix), we needed to re-organize some data sets to ensure that a consistent representation from the DWI data was maintained.

reckbo commented 7 years ago

Great, thanks.

ihnorton commented 5 years ago

Due to the fact that the BVEC and BVAL information is implicitly in an LAS corrdinate system (and the fact that the measurement frame is implicitly an identity matrix

@hjmjohnson I'd like to re-open this to discuss the current behavior for FSL Nifti -> NRRD

1) measurement frame = identity behavior for DWIConvert output when converting 2) writing FSL bvec file with g[i] = inv(MF) * g_orig[i]

For (1):

For (2): What is the reason for using inv(measurement frame)? Considering that the bvec is expressed with respect to the image axes, shouldn't the transform that takes the vector from image axes to world space be just measurement frame, not inv(mf)? As a concrete example, here is a comparison of two tensor maps computed with FDT, using output from dcm2niix [1] and DWIConvert [2].

[1] image

[2] image

neurolabusc commented 5 years ago

In addition to the links provided by @ihnorton, I would suggest this link. Fortunately, DWI data is is virtually always acquired axially, but if you do encounter coronal or sagittal acquisitions, I would be very cautious of hard coding the LAS reorientation, as Eddy assumes that slices are the 3rd dimension and altering this will impact options like --repol and --slspec.