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

t2w scan defacing #20

Open
leej3 opened this issue Feb 26, 2018 · 11 comments
Open

t2w scan defacing #20

leej3 opened this issue Feb 26, 2018 · 11 comments

Comments

@leej3
Copy link
Contributor

leej3 commented Feb 26, 2018

Hi I was wondering about the best way to get robust T2w defacing and thoughts on whether changing the code a bit would be desired.

Currently the best way seems to be to deface a T1w scan and then pass the result as a template for subsequent pydeface run for defacing a T2w scan. Alternatively one could register all scans to the T1w scans first and then use the --applyto option. My questions are:
a) Would it be worthwhile integrating this into a more convenient interface i.e. pass pydeface a T1w scan and a list of other scans. Pydeface would first deface the T1w and then use the result as a template for the subsequent scans. Effectively a --applyto_with_reg flag.
b) Would it be worthwhile to use something like epi_reg to make this more robust?
c) Can I submit a pull request documenting outlining the best way to deface these types of scans. My naive attempts had me just defacing T2w with the default template and hacking off large portions of the brain.

@chrisgorgo
Copy link
Contributor

  • I think it should be rather straightforward to define a face mask in the MNI 2009c T2w atlas and use that as coregistration target for T2w scans.
  • As for usability it might be good to provide a BIDS App for defacing (that would detect what data is in the dataset and apply appropriate procedures)
  • All PRs are welcome!

@leej3
Copy link
Contributor Author

leej3 commented Feb 26, 2018

Cool. I like the idea of the bids app alright. I'll have a go at that.

@chrisgorgo
Copy link
Contributor

chrisgorgo commented Feb 28, 2018 via email

@leej3
Copy link
Contributor Author

leej3 commented Mar 8, 2018

I have not got round to this yet. Still planning on it though. To extend this tool to other populations - pediatric, toddler, neurodegenerative disease patients - one may not have access to templates across multiple modalities in which case the apply_to_with_reg flag would be a useful plan B. Otherwise the code base would start filling up with templates...

@dmd
Copy link

dmd commented Apr 13, 2021

3 years later - is there an established way to do this in pydeface, or have people moved on to other tools, or what?

@leej3
Copy link
Contributor Author

leej3 commented Apr 13, 2021

It’s a two step process, and was not tidied up beyond that.

@AdamT has worked with this more recently, any tips?

@AdamT
Copy link

AdamT commented Apr 15, 2021

It’s a two step process, and was not tidied up beyond that.

@AdamT has worked with this more recently, any tips?

@leej3 I believe I've been mistagged as I'm not involved with this project. Cheers 👋

@ofgulban
Copy link
Collaborator

@dmd , I think one established way is: "one could register all scans to the T1w scans first and then use the --applyto option". Attaching an old pull request in case if it helps: #15

@agt24
Copy link

agt24 commented Apr 20, 2021

Yeah, this worked well for us on a recent dataset. @Arshitha did the scripting. @Arshitha can you share the command line options you used?

@Arshitha
Copy link

@agt24 I've documented the pydeface workflow we used here The jupyter notebook has all the flags with a brief explanation of the modifications we made. Happy to answer any questions if this doesn't help.

@agt24
Copy link

agt24 commented Feb 7, 2022

@Arshitha and @ericearl were chatting about this today. In that conversation, I realized there are some very non-obvious and non-documented details about our pipeline that took me some head scratching to recall the rationale for. So I thought I'd document them here. Here's the command line calls from the notebook @Arshitha referenced above:

PART 1: 
1. `fslmaths facemask.nii.gz -binv facemask_inv` (inverting default facemask)
2. `pydeface sub-ON01802_ses-01_acq-mprage_run-01_T1w.nii.gz --facemask ../../pydeface-defaults/data/facemask-inv.nii.gz --nocleanup --verbose --debug > T1w-deface-facemask-inv.txt`
3. `fslmaths sub-ON01802_ses-01_acq-mprage_run-01_T1w_pydeface_mask.nii.gz -binv inverted-T1w-pydeface-mask`
4. `fslmaths inverted-T1w-pydeface-mask.nii.gz -mul sub-ON01802_ses-01_acq-mprage_run-01_T1w.nii.gz sub-ON01802_ses-01_acq-mprage_run-01_T1w-new-mask-defaced.nii.gz`

PART 2: 
a. FLAIR 
- `pydeface sub-ON01802_ses-01_acq-2d_run-01_FLAIR.nii.gz --template sub-ON01802_ses-01_acq-mprage_run-01_T1w.nii.gz --facemask inverted-T1w-pydeface-mask.nii.gz --nocleanup --verbose --force --debug > flair_pydeface.txt`
- `fslmaths sub-ON01802_ses-01_acq-2d_run-01_FLAIR_pydeface_mask.nii.gz -binv inverted-flair-pydeface-mask`
- `fslmaths inverted-flair-pydeface-mask -mul sub-ON01802_ses-01_acq-2d_run-01_FLAIR.nii.gz sub-ON01802_ses-01_acq-2d_run-01_FLAIR_new-mask-defaced.nii.gz` 

b. T2w 
- same as above. Repeat for all modalities

We did the fslmaths inverting and uninverting before and after pydeface to deal with a problem we encountered on scans with largish fields of view (FOV). When the facemask was transformed into the space of the input ToBeDefaced volume, voxels outside of the FOV of the original facemask volume showed up as 1's instead of zeros. This sometimes caused some non-face portions of the input ToBeDefaced volume to be masked out which caused problems in later processing. (I'll post some screenshot if/when I can find them)

I'm curious if others have encountered this issue and if there are other approaches to address it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants