Last active
February 12, 2020 16:56
-
-
Save alexfoias/53b5a3b80502737edabb68e8e33d44b9 to your computer and use it in GitHub Desktop.
Error deface T2w
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> library(RNifti) | |
> library(fslr) | |
> getwd() | |
[1] "/Users/alfoi/Desktop/tst_r" | |
> setwd("/Users/alfoi/Desktop/tst_r") | |
> fname = "sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz" | |
> 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) | |
trying URL 'https://openneuro.org/crn/datasets/ds002393/snapshots/1.0.2/files/sub-chibaIngenia:anat:sub-chibaIngenia_T2w.nii.gz' | |
downloaded 6.4 MB | |
> img = RNifti::readNifti(fname) | |
> out = face_removal_mask(fname) | |
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 "/Users/alfoi/Desktop/tst_r/sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz" -out "/var/folders/_8/wq4mlll97hn7w0hw84bs4stw0000gn/T//RtmpGKYsIW/file2aa03341f9c7" -dof 12 -omat "/var/folders/_8/wq4mlll97hn7w0hw84bs4stw0000gn/T//RtmpGKYsIW/file2aa054f354c3.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/_8/wq4mlll97hn7w0hw84bs4stw0000gn/T/RtmpGKYsIW/file2aa076cb4377.nii.gz" -ref "/Users/alfoi/Desktop/tst_r/sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz" -applyxfm -init "/var/folders/_8/wq4mlll97hn7w0hw84bs4stw0000gn/T//RtmpGKYsIW/file2aa054f354c3.mat" -interp nearestneighbour -out "/var/folders/_8/wq4mlll97hn7w0hw84bs4stw0000gn/T//RtmpGKYsIW/file2aa03075921b" | |
> out_img = readnii(out) | |
> xx = which(out_img == 0, arr.ind = TRUE) | |
> | |
> dim3 = 1:(min(xx[,3]) + floor( (max(xx[,3]) - min(xx[,3]))/2)) | |
Error in 1:(min(xx[, 3]) + floor((max(xx[, 3]) - min(xx[, 3]))/2)) : | |
NA/NaN argument | |
In addition: Warning messages: | |
1: In min(xx[, 3]) : no non-missing arguments to min; returning Inf | |
2: In max(xx[, 3]) : no non-missing arguments to max; returning -Inf | |
3: In min(xx[, 3]) : no non-missing arguments to min; returning Inf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RNifti) | |
library(fslr) | |
getwd() | |
setwd("/Users/alfoi/Desktop/tst_r") | |
fname = "sub-chibaIngeniasub-chibaIngenia_T2w.nii.gz" | |
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) | |
out = face_removal_mask(fname) | |
out_img = readnii(out) | |
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 = dim2, dim3 = dim3) | |
eg = as.matrix(eg) | |
new_mask = out_img | |
new_mask[eg] = 0 | |
final_img = img * new_mask | |
outfile = gsub("_T2w.nii.gz", "_T2w_defaced.nii.gz",image) | |
writeNifti(final_img, file = outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment