An AFNI function for "out of FOV" detection?

Hi AFNI gurus:
I am wondering if there is a convenient AFNI function/command for determining whether a brain is not entirely contained in the box of FOV. The attaching picture shows such a case where some of the occipital lobe is missing.

Thank you so much for your help!

zzzOutOfBox.jpg

There are probably lots of ways to test for this. I wrote this little script to do this. It tests if reducing the box of the dataset by one slice in all directions except in the inferior direction and then expanding back to the original has any differences. It doesn’t check for anything “brain” specific. This might not be as useful for the typically tighter EPI coverage, for instance. Alternatively, one could check for brain atlas or mask coverage by alignment to a template. Inverting the transformation to the native space and checking against a one slice larger could reveal the brain mask not completely fitting in the native volume. That has the larger requirement of alignment working, and for very partial volumes that would be more problematic.

#!/bin/tcsh

find a general mask - clustering but not brain specific

3dAutomask -overwrite -apply_prefix anat_am.nii.gz anat+orig.

put into one slice smaller volume in all directions except inferior

(where anatomical datasets typically include the neck)

3dZeropad -S -1 -A -1 -P -1 -R -1 -L -1 -overwrite -prefix anat_zpm1.nii.gz anat_am.nii.gz

bump back up to original size

3dZeropad -master anat_am.nii.gz -prefix anat_zp_origsize.nii.gz -overwrite anat_zpm1.nii.gz

calculate voxels that are different

3dcalc -a anat_am.nii.gz -b anat_zp_origsize.nii.gz -expr ‘not(equals(a,b))’ -prefix edgetest.nii.gz -overwrite
#output includes this line - which could be used too

*+ WARNING: output sub-brick 0 is all zeros!

set fovtest = 3dBrickStat -count -non-zero edgetest.nii.gz
if ($fovtest != “0”) then
echo “brain mask goes to edge”
else
echo “brain mask is not on edge”
endif