Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of a LORIS tool to deface structural images and register the defaced images back into LORIS #366

Merged
merged 18 commits into from
Feb 19, 2019

Conversation

cmadjar
Copy link
Collaborator

@cmadjar cmadjar commented Dec 14, 2018

Description

This PR adds a new tool that will allow defacing of the structural images listed in the Config module under the imaging pipeline section in the new field called modalities_to_deface (See PR aces/Loris#4232 on the LORIS side for the SQL patch).

Note that the script deface_minipipe.pl in uploadNeuroDB/bin has been taken out of the BIC EZminc GitHub repo (https://github.com/BIC-MNI/EZminc/tree/ITK4/scripts).

Screenshot of a defaced scan:
defaced

How to use the tool

  1. Make sure to populate the configuration modalities_to_deface in the imaging pipeline section of the Configuration module with all scan types that you wish to deface (typically, T1W, T2W, T2*, FLAIR and other 3D structural images)

  2. To run the tool, go to the tools directory and run:
    perl run_defacing_script.pl -profile <profile> [ -sessionIDs <list of sessionIDs> ]
    Note that if the -sessionIDs is not passed to the script, it will deface images from all sessions with the modalities to deface.

Note that the defaced images will be registered in LORIS as modality-defaced (where modality is replaced by t1, t2, flair...). The new MRI scan type called modality-defaced is automatically created in the mri_scan_type table by run_defacing_script.pl based on the name of the modality to deface.

Special notes for multi-contrast acquisitions:

At the top of the script, 2 variables have been implemented and can be customized:

1. %SPECIAL_ACQUISITIONS_FILTER:

For acquisitions such as fieldmaps, a phase and two magnitude files are available. We only want to deface the magnitude files as the phase file does not have a face and we don't want to alter the phase image. To differentiate between the phase and magnitude files, we need to use the acquisition:image_type MINC header for which the value will be:

  • ORIGINAL\\PRIMARY\\M\\ND for the magnitude files
  • ORIGINAL\\PRIMARY\\P\\ND for the phase file

Therefore, to only deface the magnitude fieldmap images, we need to specify the value of acquisition:image_type in the constant variable %SPECIAL_ACQUISITIONS_FILTER at the top of the script like that:

my %SPECIAL_ACQUISITIONS_FILTER = (
    'fieldmap'      => 'ORIGINAL\\PRIMARY\\M\\ND'
);

In the script, this constant variable also shows examples for MP2RAGE and multi-echo acquisitions.

2. @MULTI_CONTRAST_ACQUISITIONS_BASE_NAMES

The @MULTI_CONTRAST_ACQUISITIONS_BASE_NAMES variable will store the base names of multi-contrast acquisitions such as MP2RAGE, qT2star or fieldmap. These will allow to call the deface_minipipe.pl tool properly for multi-contrast acquisition (a.k.a. fieldmap_file1,fieldmap_file2). Calling deface_minipipe.pl with images separated by , will tell the script not to create 2 XFMs (one for each fieldmap file) but instead reuse the XFM from fieldmap_file1 to register fieldmap_file2.

Notes for existing projects

If you desire to use this new tool, make sure you have:

  • downloaded and installed the bic-mni-models anatomical template library and the beast library from the MINC tools in /opt/minc/ (https://bic-mni.github.io/#data-files-and-models)
  • added the two following variables to your environment file so that the scripts can find the MNI models (replace %MINC_TOOLKIT_DIR% by the path to your MINC toolkit install):
# for the defacing scripts
export BEASTLIB=%MINC_TOOLKIT_DIR%/../share/beast-library-1.1
export MNI_MODELS=%MINC_TOOLKIT_DIR%/../share/icbm152_model_09c

Additional checks before running the script:

  • make sure which deface_minipipe.pl is returning the following $LORIS-MRI/uploadNeuroDB/bin/deface_minipipe.pl script and not the one present in the MINC toolkit (/opt/minc/$VERSION) as LORIS-MRI is using the version of deface_minipipe.pl under development (which have not yet been released with the MINC tools). If which deface_minipipe.pl is not pointing to the correct script, you will need to update your $PATH bash variable to make sure $LORIS-MRI/uploadNeuroDB/bin is the first path mentioned in the variable.

See also

# (arguments without ,)

# create the directory where the final outputs will be saved
mkdir($output_dir) unless (-e $output_dir);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of the mkdir command should be checked and an error message issued if it failed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
Copy link
Collaborator Author

@cmadjar cmadjar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @nicolasbrossard for your review!!

One note, you commented on the script I copied from the EZminc BIC repo so I did not integrate all your comments (like the exit code for example which is not implemented on the MINC tool side I believe). Since there are portions of the script I modified to make it more generic (it got merge before the holidays on the EZminc repo), I included your feedback on the parts I modified and will commit the changes to the EZminc repo so they can have it as well.

However, if you could review the script in the tools directory called run_deface_script.pl, that would be awesome!

Thank you so much!!

uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
uploadNeuroDB/bin/deface_minipipe.pl Show resolved Hide resolved
# (arguments without ,)

# create the directory where the final outputs will be saved
mkdir($output_dir) unless (-e $output_dir);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

driusan pushed a commit to aces/Loris that referenced this pull request Jan 7, 2019
…ng tool (#4232)

This adds to the imaging_pipeline section of the Config module 2 fields needed for the imaging defacing tool:

- reference_scan_type_for_defacing: the reference image that will be used for registration (typically the t1w modality)
- modalities_to_deface: multi-line options to list all 3D modalities that need to be defaced (for example t1w, flair, pd, t2w...)

This goes with the LORIS-MRI PR: aces/Loris-MRI#366
tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Show resolved Hide resolved
Copy link
Collaborator Author

@cmadjar cmadjar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolasbrossard Thank you very much for your review. I included your feedback in the next commit. Ready for another review! :)

tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@cmadjar cmadjar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PapillonMcGill Thank you for the comments. They should all be fixed in the last commit.

tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
tools/run_defacing_script.pl Outdated Show resolved Hide resolved
docs/scripts_md/run_defacing_script.md Outdated Show resolved Hide resolved
docs/scripts_md/run_defacing_script.md Outdated Show resolved Hide resolved
docs/scripts_md/run_defacing_script.md Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@cmadjar cmadjar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PapillonMcGill thank you for the review. It should be taken care of in the last commit.

docs/scripts_md/run_defacing_script.md Outdated Show resolved Hide resolved
docs/scripts_md/run_defacing_script.md Outdated Show resolved Hide resolved
@PapillonMcGill
Copy link

LGTM

README.md Outdated Show resolved Hide resolved
@PapillonMcGill
Copy link

no more objection!

@cmadjar cmadjar added this to the 20.3 milestone Feb 14, 2019
@cmadjar
Copy link
Collaborator Author

cmadjar commented Feb 14, 2019

@nicolasbrossard all your previous comments have been taken care of. Please re-review at your convenience. Thanks!

@@ -1280,7 +1280,9 @@ sub compute_hash {
$ctx->add($file->getParameter('patient:birthdate')); # Patient DOB
$ctx->add($file->getParameter('study_instance_uid')); # StudyInstanceUID
$ctx->add($file->getParameter('series_description')); # SeriesDescription
$ctx->add($file->getParameter('processing:intergradient_rejected'));
if ($file->getParameter('processing:intergradient_rejected')) {
Copy link
Collaborator

@nicolasbrossard nicolasbrossard Feb 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know if this is possible but if parameter processing:intergradient_rejected exists and is either '' or 0, then this test evaluates to false. Is this what you want?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!!! Should be corrected in the next commit.

Copy link
Collaborator

@nicolasbrossard nicolasbrossard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I do have a question (see comments above).

@cmadjar cmadjar merged commit 2bb7def into aces:minor Feb 19, 2019
@cmadjar cmadjar deleted the addition_of_defacing_tool branch February 19, 2019 20:47
kchatpar pushed a commit to kchatpar/Loris that referenced this pull request Apr 15, 2019
…ng tool (aces#4232)

This adds to the imaging_pipeline section of the Config module 2 fields needed for the imaging defacing tool:

- reference_scan_type_for_defacing: the reference image that will be used for registration (typically the t1w modality)
- modalities_to_deface: multi-line options to list all 3D modalities that need to be defaced (for example t1w, flair, pd, t2w...)

This goes with the LORIS-MRI PR: aces/Loris-MRI#366
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants