Open stnava opened 3 years ago
script for brain extraction of 95 region data
library( ANTsR )
library( ANTsRNet )
fns=Sys.glob("*[0-9].nii.gz")
fnss=Sys.glob("*[0-9]*seg.nii.gz")
for ( x in 1:length(fns) ) {
ofn = paste0( tools::file_path_sans_ext(fns[x],T), "_brain.nii.gz" )
print(paste(fns[x],fnss[x]))
img = antsImageRead( fns[x] )
seg = antsImageRead( fnss[x] )
bxt = thresholdImage( seg, 1, Inf ) %>% morphology( "close", 10 ) %>% iMath("FillHoles")
antsImageWrite( img * bxt, ofn )
}