Closed alexfoias closed 4 years ago
Can you provide an MWE https://stackoverflow.com/help/minimal-reproducible-example ? Also, you can either find the mask by looking at voxels that are different from the non-masked image or you can dig into the temporary files (currently) that are generated https://github.com/poldracklab/pydeface/blob/master/pydeface/utils.py#L116. You can then cut the mask to where it needs to stop (aka the neck).
Looking a bit more I'd recommend setting --nocleanup
so that the mask is output from the operation so you can inspect the mask and you may be able to manipulate these or figure out some rules from these.
@muschellij2 I followed your advice and I saved the mask. The mask doesn't include the complete VOI. Do I have to manually modify the mask to include the complete neck region or is there a parameter that I could change to expand the coverage?
Again, almost impossible to diagnose without an MWE https://stackoverflow.com/help/minimal-reproducible-example ?
Is this what you're looking for? This relies on my implementation of pydeface
in the R package fslr
, which is almost identical. The extension to the rest of the image
library(RNifti)
library(fslr)
#> Loading required package: oro.nifti
#> oro.nifti 0.10.1
#>
#> Attaching package: 'oro.nifti'
#> The following object is masked from 'package:RNifti':
#>
#> origin
#> Loading required package: neurobase
fname = "sub-chiba750_anat_sub-chiba750_T1w.nii.gz"
download.file(url = paste0("https://openneuro.org/crn/datasets/ds002393/",
"snapshots/1.0.2/files/",
"sub-chiba750:anat:sub-chiba750_T1w.nii.gz"),
destfile = fname)
img = RNifti::readNifti(fname)
out = face_removal_mask(fname)
#> Warning in get.fsl(): Setting fsl.path to /usr/local/fsl
#> Warning in get.fsloutput(): Can't find FSLOUTPUTTYPE, setting to NIFTI_GZ
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/flirt -in "/usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz" -ref "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpK4U4ug/reprex17ffa74bf4484/sub-chiba750_anat_sub-chiba750_T1w.nii.gz" -out "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpKjcGt4/file58d7925ddcf" -dof 12 -omat "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpKjcGt4/file58d19f2c8d.mat" -cost mutualinfo
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/flirt -in "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpKjcGt4/file58dbe034b1.nii.gz" -ref "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpK4U4ug/reprex17ffa74bf4484/sub-chiba750_anat_sub-chiba750_T1w.nii.gz" -applyxfm -init "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpKjcGt4/file58d19f2c8d.mat" -interp nearestneighbour -out "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpKjcGt4/file58d25057f2c"
out_img = readnii(out)
ortho2(img)
Here is my extension. The idea is to find all the indices in x, y, and z-planes that are in the mask. We then extend down in the z-plane (dim3
) and "forward" in the y-plane (dim2
) and show the masked output:
xx = which(out_img == 0, arr.ind = TRUE)
dim3 = 1:(min(xx[,3]) + floor( (max(xx[,3]) - min(xx[,3]))/2))
dim2 = min(xx[,2]):dim(out_img)[2]
# eg = expand.grid(dim1 = unique(xx[,1]),
# dim2 = unique(xx[,2]), dim3 = dim3)
eg = expand.grid(dim1 = unique(xx[,1]),
dim2 = dim2, dim3 = dim3)
eg = as.matrix(eg)
new_mask = out_img
new_mask[eg] = 0
final_img = img * new_mask
ortho2(final_img)
Created on 2020-01-23 by the reprex package (v0.3.0.9001)
This may be more clear as to what is getting added.
library(RNifti)
library(fslr)
#> Loading required package: oro.nifti
#> oro.nifti 0.10.1
#>
#> Attaching package: 'oro.nifti'
#> The following object is masked from 'package:RNifti':
#>
#> origin
#> Loading required package: neurobase
fname = "sub-chiba750_anat_sub-chiba750_T1w.nii.gz"
download.file(url = paste0("https://openneuro.org/crn/datasets/ds002393/",
"snapshots/1.0.2/files/",
"sub-chiba750:anat:sub-chiba750_T1w.nii.gz"),
destfile = fname)
img = RNifti::readNifti(fname)
out = face_removal_mask(fname)
#> Warning in get.fsl(): Setting fsl.path to /usr/local/fsl
#> Warning in get.fsloutput(): Can't find FSLOUTPUTTYPE, setting to NIFTI_GZ
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/flirt -in "/usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz" -ref "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpK4U4ug/reprex17ffa365ce2a8/sub-chiba750_anat_sub-chiba750_T1w.nii.gz" -out "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpwhfPxR/file5f0382ef3d6" -dof 12 -omat "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpwhfPxR/file5f042b7e932.mat" -cost mutualinfo
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/flirt -in "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpwhfPxR/file5f043b9ef4f.nii.gz" -ref "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpK4U4ug/reprex17ffa365ce2a8/sub-chiba750_anat_sub-chiba750_T1w.nii.gz" -applyxfm -init "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpwhfPxR/file5f042b7e932.mat" -interp nearestneighbour -out "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpwhfPxR/file5f0128a836b"
out_img = readnii(out)
ortho2(img)
ortho2(img, out_img)
xx = which(out_img == 0, arr.ind = TRUE)
dim3 = 1:(min(xx[,3]) + floor( (max(xx[,3]) - min(xx[,3]))/2))
dim2 = min(xx[,2]):dim(out_img)[2]
# eg = expand.grid(dim1 = unique(xx[,1]),
# dim2 = unique(xx[,2]), dim3 = dim3)
eg = expand.grid(dim1 = unique(xx[,1]),
dim2 = dim2, dim3 = dim3)
eg = as.matrix(eg)
new_mask = out_img
new_mask[eg] = 0
final_img = img * new_mask
ortho2(final_img)
ortho2(img, new_mask == 0)
Created on 2020-01-23 by the reprex package (v0.3.0.9001)
@muschellij2 Thanks for your help. I tried to follow the instructions above, but I ran into trouble .
I noticed that I have a different version of fslr & oro.nifti than you.
Yeah, I'm trying to update the packages on my end, I thikn oyu need to install:
remotes::install_github("muschellij2/oro.nifti")
Thanks. I managed to reproduce the results for the give case. I'll try to create a script to do a batch processing for the complete dataset.
@muschellij2 I tried to run the script for T2w, but I ran into some issues. Here is the output: https://gist.github.com/alexfoias/53b5a3b80502737edabb68e8e33d44b9
So the overall process works on the fact you can register a brain to a brain, or really a head to a head. That image you are downloading really isn't a brain/head, but more like half a brain a lot of the spinal cord. Not only that, the image is very narrow and not a full head/next. The affine transformation won't handle this well and you need to use a different approach. Best, John
On Wed, Feb 12, 2020 at 11:56 AM alexfoias notifications@github.com wrote:
@muschellij2 https://github.com/muschellij2 I tried to run the script for T2w, but I ran into some issues. Here is the output: https://gist.github.com/alexfoias/53b5a3b80502737edabb68e8e33d44b9
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/poldracklab/pydeface/issues/27?email_source=notifications&email_token=AAIGPLVSASGG2JTJCIAS5ATRCQS5JA5CNFSM4HKWF56KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELRQ4XY#issuecomment-585305695, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLSFON7OE2S4PQRKAI3RCQS5JANCNFSM4HKWF56A .
Also, someone from @poldrack @poldracklab probably should weigh in.
Agree with @muschellij2 's previous comment. Defacing does not work by default because your coverage is not a conventional brain image. I would recommend using --template
and --facemask
flags in addition to setup a custom spine-imaging-focused face mask. For instance, if you have 10 subjects, take one of the subjects, draw manually a face mask and use the anatomical image of this subject with the --template
flag, and the face mask with the --facemask
flag when defacing other subjects. Your pydeface command should look sth like this at the end:
pydeface /path/to/sub-02.nii --template /path/to/sub-01.nii --facemask /path/to/sub-01_facemask.nii
pydeface /path/to/sub-03.nii --template /path/to/sub-01.nii --facemask /path/to/sub-01_facemask.nii
Here --facemask /path/to/sub-01_facemask.nii
should be created by you manually using sth like ITK-SNAP or fsleyes/fslview.
(Note: I am not from @poldrack 's lab, but I put these extra flags to the command line interface to cover for such use cases.)
@alexfoias with regards to T2w image defacing, see the --applyto
flag sections of this pull request: #15
If you have higher signal-to-noise ratio T1w images together with T2w images, you might want to consider using this --applyto
flag.
You can make some adaptations, but you really need to see the above comments, but here's something that works for this one file (need to extend mask):
library(RNifti)
library(fslr)
#> Loading required package: oro.nifti
#> oro.nifti 0.10.2
#>
#> Attaching package: 'oro.nifti'
#> The following object is masked from 'package:RNifti':
#>
#> origin
#> Loading required package: neurobase
library(extrantsr)
#>
#> Attaching package: 'extrantsr'
#> The following object is masked from 'package:neurobase':
#>
#> zero_pad
#> The following objects are masked from 'package:oro.nifti':
#>
#> origin, origin<-
#> The following object is masked from 'package:RNifti':
#>
#> origin
fname = file.path(tempdir(),
"sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz")
if (!file.exists(fname)) {
download.file(url = paste0(
"https://openneuro.org/crn/datasets/ds002393/",
"snapshots/1.0.2/files/",
"sub-chibaIngenia:anat:sub-chibaIngenia_T2w.nii.gz"),
destfile = fname)
}
img = RNifti::readNifti(fname)
tfname = mni_fname(mm = "1")
#> Warning in get.fsl(): Setting fsl.path to /usr/local/fsl
#> Warning in get.fsloutput(): Can't find FSLOUTPUTTYPE, setting to NIFTI_GZ
face_fname = mni_face_fname(mm = "1")
face = readnii(face_fname)
timg = readnii(tfname)
timg = copyNIfTIHeader(timg, timg[(91-30):(91+30), , 1:70])
face = copyNIfTIHeader(face, face[(91-30):(91+30), , 1:70])
noneck <- double_remove_neck(
fname,
template.file = file.path(fsldir(),
"data/standard", "MNI152_T1_1mm_brain.nii.gz"),
template.mask = file.path(fsldir(),
"data/standard", "MNI152_T1_1mm_brain_mask.nii.gz"))
#> # Registration to template
#> # Swapping Dimensions
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslhd "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslorient -getorient "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslorient -swaporient "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa35f6f8ac/sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslswapdim "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa35f6f8ac/sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz" RL PA IS "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa693fffe1";
#> # Running Registration of file to template
#> # Applying Registration output is
#> $warpedmovout
#> antsImage
#> Pixel Type : float
#> Components Per Pixel: 1
#> Dimensions : 63x320x320
#> Voxel Spacing : 0.799999237060547x0.800000011920929x0.800000011920929
#> Origin : -13.47086 120.9473 -144.1494
#> Direction : 0.9991751 -0.02116131 0.03466073 -0.02100112 -0.9997671 -0.004979392 -0.03475802 -0.00424737 0.9993867
#>
#>
#> $warpedfixout
#> antsImage
#> Pixel Type : float
#> Components Per Pixel: 1
#> Dimensions : 182x218x182
#> Voxel Spacing : 1x1x1
#> Origin : -90 126 -72
#> Direction : 1 0 0 0 -1 0 0 0 1
#>
#>
#> $fwdtransforms
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa192704440GenericAffine.mat"
#>
#> $invtransforms
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa192704440GenericAffine.mat"
#>
#> $prev_transforms
#> character(0)
#> # Applying Transformations to file
#> # Applying Transforms to other.files
#> # Writing out file
#> # Writing out other.files
#> # Removing Warping images
#> # Reading data back into R
#> # Reading in Transformed data
#> # Dropping slices not in mask
#> # Swapping Dimensions Back
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslorient -swaporient "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa6c3724a6.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslswapdim "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa6c3724a6.nii.gz" LR PA IS "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa184745cb";
#> # Registration to template
#> # Swapping Dimensions
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslhd "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa6f371ee0.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslorient -getorient "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa6f371ee0.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslorient -swaporient "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaadc3d81a/file6aaa6f371ee0.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslswapdim "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaadc3d81a/file6aaa6f371ee0.nii.gz" RL PA IS "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa34a09a05";
#> # Running Registration of file to template
#> # Applying Registration output is
#> $warpedmovout
#> antsImage
#> Pixel Type : float
#> Components Per Pixel: 1
#> Dimensions : 63x320x320
#> Voxel Spacing : 0.799999237060547x0.800000011920929x0.800000011920929
#> Origin : -13.47086 120.9473 -144.1494
#> Direction : 0.9991751 -0.02116131 0.03466073 -0.02100112 -0.9997671 -0.004979392 -0.03475802 -0.00424737 0.9993867
#>
#>
#> $warpedfixout
#> antsImage
#> Pixel Type : float
#> Components Per Pixel: 1
#> Dimensions : 182x218x182
#> Voxel Spacing : 1x1x1
#> Origin : -90 126 -72
#> Direction : 1 0 0 0 -1 0 0 0 1
#>
#>
#> $fwdtransforms
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa53048b30GenericAffine.mat"
#>
#> $invtransforms
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa53048b30GenericAffine.mat"
#>
#> $prev_transforms
#> character(0)
#> # Applying Transformations to file
#> # Applying Transforms to other.files
#> # Writing out file
#> # Writing out other.files
#> # Removing Warping images
#> # Reading data back into R
#> # Reading in Transformed data
#> # Dropping slices not in mask
#> # Swapping Dimensions Back
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslorient -swaporient "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa14448914.nii.gz"
#> FSLDIR='/usr/local/fsl'; PATH=${FSLDIR}/bin:${PATH};export PATH FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; ${FSLDIR}/bin/fslswapdim "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmppwGYy3/file6aaa14448914.nii.gz" LR PA IS "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa1f838a71";
reg = registration(
filename = timg,
template.file = noneck,
typeofTransform = "Rigid")
#> # Running Registration of file to template
#> # Applying Registration output is
#> $fwdtransforms
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa46ce1e1d0GenericAffine.mat"
#>
#> $invtransforms
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa46ce1e1d0GenericAffine.mat"
#>
#> $prev_transforms
#> character(0)
#> # Applying Transformations to file
#> [1] "-d"
#> [2] "3"
#> [3] "-i"
#> [4] "<pointer: 0x7f80bf75cd20>"
#> [5] "-o"
#> [6] "<pointer: 0x7f80c6168d60>"
#> [7] "-r"
#> [8] "<pointer: 0x7f80bf79e8f0>"
#> [9] "-n"
#> [10] "linear"
#> [11] "-t"
#> [12] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa46ce1e1d0GenericAffine.mat"
#> # Writing out file
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmppwGYy3/file6aaa74f610e0.nii.gz"
#> # Reading data back into R
out_img = ants_apply_transforms(moving = 1 - face,
fixed = noneck,
transformlist = reg$fwdtransforms,
interpolator = "nearestNeighbor")
ortho2(img, out_img)
xx = which(out_img == 1, arr.ind = TRUE)
dim3 = 1:(min(xx[,3]) + floor( (max(xx[,3]) - min(xx[,3]))/2))
dim2 = min(xx[,2]):dim(out_img)[2]
# eg = expand.grid(dim1 = unique(xx[,1]),
# dim2 = unique(xx[,2]), dim3 = dim3)
eg = expand.grid(dim1 = unique(xx[,1]),
dim2 = dim2, dim3 = dim3)
eg = as.matrix(eg)
new_mask = out_img
new_mask[eg] = 1
ortho2(img, new_mask)
ortho2(img, 1 - new_mask)
Created on 2020-02-12 by the reprex package (v0.3.0.9001)
@muschellij2 The proposed solution works for me. Thank you for your help. I managed to face my dataset. We can close this issue.
I tried to deface some T1w images (brain and spine up to C7 level). The problem is that the images are cropped to C2 level in the spine.
Is there a way to enlarge the FOV of the pydeface ?