Child pages
  • Generating deformation fields

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. A target determinant can be created from a mask or structure label. In the following example the file striatum.mnc is a binary file where voxels with the value 1 belong to the striatum and voxels with the value 0 are non-striatum voxels. The output determinant file will shrink the striatum by 20%:

    No Format
    > minccalc -expression 'if(A[0] == 1) {out = 0.8;} else {out = 1;}' striatum.mnc striatum_determinant_20_percent_shrinkage.mnc

    The method above would be the most used (and probably most useful) way to create a determinant, because in general you will have fairly specific ROI that you want to change. Alternatively, you can use a program that will create a target determinant in the form of an octahedron. At the moment, this program is very limited in the kinds of determinants it can create, because only octahedrons can be created. The parameters are given in voxel space. The output determinant will shrink the octahedron area by 40%:

    No Format
    # base_test_file.mnc -- is used to determine the dimensions/resolution of the output file
    # the center (-c) is given in voxel coordinates
    > create_determinant.py -c 10,10,10 -d 0.6 -r 5 base_test_file.mnc base_test_file_det_0.6_at_10_10_10_radius_5.mnc
    

    Alternatively,

  2. (optional) If you created several areas that require change, merge these into one file. Example for two input files:

    No Format
    > minccalc -expression 'if(A[0] == 1 && A[1] == 1) {out = 1;} else if(A[0] == 1 && A[1] != 1) {out = A[1];} else if(A[0] != 1 && A[1] == 1) {out = A[0];} else {out = A[0] + A[1];}' base_test_file_det_10_10_10_r_5.mnc base_test_file_det_20_20_20_r_3.mnc base_test_file_det_combined.mnc
    
  3. (optional) Blur the final determinant file, example:

    No Format
    > blur_determinant.py -b 0.24 base_test_file_det_combined.mnc base_test_file_det_combined_blur_0.24.mnc
    
  4. Create a tolerance map; a map indicating voxels that are allowed to grow and shrink semi-freely (e.g., CSF, background). The jacobian determinant for a voxel indicates the amount of growth or shrinkage at that voxel. If the value is 1, that means no change, if it is 2 the voxel is doubled in volume/size, and if it is 0.5, the voxel is half the size of its original size. Given that the range of Jacobian runs from (0,infinity), the meaning of a value in the tolerance map is as follows
    • Tolerance map value 0: voxel is only allowed to change within the limits of the overall tolerance (set by -t)
    • Tolerance map value 1: voxel's determinant can range from 0.5-2, i.e., twice the size or half the size
    • Tolerance map value 2: voxel's determinant can range from 0.333-3, i.e., three times the size or one third of the size
    • etc.

      No Format
      # In this example, we have access to a segmentation where the lateral ventricles have label values 57 and 77.
      # We use the program minc_label_ops to segment out these two structures from the segmentation and binarize them
      # minc_label_ops is part of: https://github.com/Mouse-Imaging-Centre/minc-stuffs
      > minc_label_ops --select=57,77 --binarize brain_atlas_labels.mnc lateral_ventricles.mnc
      
      # you can also create a ring of tolerance space around the brain if you have a brain mask. Using the atlas you can run
      # the following. The -successive flag for mincmorph allows you to specify multiple operations in sequence. The first
      # part B[0.5:999] will binarize the file. All voxels with a value between 0.5 and 999 will become 1, all others 0. 
      # The Ds (DDDD and DDDDDDDDDD) will then dilate (add a layer of voxels around the current "object") the shape 4 and
      # 10 times respectively.
      > mincmorph -successive B[0.5:999]DDDD brain_atlas_labels.mnc dilated_mask.mnc
      > mincmorph -successive B[0.5:999]DDDDDDDDDD brain_atlas_labels.mnc more_dilated_mask.mnc
      > minccalc -expression 'if(A[0] == 1 && A[1] == 0) {out = 1;} else {out = 0;}' more_dilated_mask.mnc dilated_mask.mnc tolerance_ring_around_brain.mnc
  5. Create a deformation field that will produce the growth and shrinkage indicated in the determinant file, example:

    No Format
    # Input files:
    # mouse_brain.mnc     --  anatomical MR scan
    # striatum.mnc        --  segmentation of the striatum, 1 indicates striatum, 0 is background
    # tolerance_space.mnc --  binary ring of voxels around the brain (1 is ring, 0 is background)
    #
    # In order to shrink the striatum by 20% we ran the following command
    > minccalc -expression 'if(A[0] == 1) {out = 0.8;} else {out = 1;}' striatum.mnc striatum_determinant_20_percent_shrinkage.mnc
    #
    # This gives us the following input files: 

    No Format
    create_deformation.py \
    -t 0.00001 \
    -i 100000 \
    -m tolerance_space.mnc \
    striatum_determinant_20_percent_shrinkage.mnc \
    deformation_field_20_percent_shrinkage_striatum.xfm
    

    If we now look at the Jacobian determinant of the deformation field we just produced, it will become clear why we need the tolerance space:

    No Format
    # calculate the determinant:
    mincblob  -det deformation_field_20_percent_shrinkage_striatum_grid.mnc  deformation_field_20_percent_shrinkage_striatum_grid_determinant.mnc
    
    # and we have to add 1 to all voxels, because internally, mincblob subtracts 1 from all calculated values...
    mincmath -add -const 1 deformation_field_20_percent_shrinkage_striatum_grid_determinant.mnc  deformation_field_20_percent_shrinkage_striatum_grid_determinant_plus_one.mnc

    This is what that file looks like:
    Image Added
    There are a couple of things to note here. The black region (striatum area) has the value 0.8001 (i.e., when you apply this transformation to your input file, it will indeed shrink the striatum by 20%). The gray areas have a Jacobian determinant of 1 meaning no change, and the light gray / white areas have Jacobian determinants ranging from 1-2. This area will grow in size when the transformation is applied. The reason this is necessary, is because the algorithm initializes a zero vector field, and iteratively updates all vectors to approximate the desired determinant. In order to shrink one area, some other area needs to grow to accommodate that change. This also means that it is important to use tolerance space in areas that either naturally change in volume, or as in this case, use areas outside of the brain altogether.
    Image Added

  6. Applying the transformation to the input file

    No Format
    # assuming that the MR brain image on the left of each of the plots is called MR.mnc, this is how you would apply the deformations:
    mincresample \
    -like MR.mnc \
    -transformation deformation_field_20_percent_shrinkage_striatum.xfm \
    MR.mnc \
    MR_striatum_20_percent_smaller.mnc
  7. To view the other available options:

    No Format
    > create_deformation.py --help

...