// Hand-written loading code to avoid too much memory consumption
orig_ref_niimg = ref_niimg
if (not isinstance(ref_niimg, str)
and not hasattr(ref_niimg, "get_data")
and not hasattr(ref_niimg, "get_fdata")
and hasattr(ref_niimg, "__iter__")):
ref_niimg = ref_niimg[0]
if not ((hasattr(ref_niimg, "get_data")
After Change
// Hand-written loading code to avoid too much memory consumption
orig_ref_niimg = ref_niimg
is_str = isinstance(ref_niimg, str)
has_get_data = hasattr(ref_niimg, "get_data")
has_get_fdata = hasattr(ref_niimg, "get_fdata")
has_iter = hasattr(ref_niimg, "__iter__")
has_affine = hasattr(ref_niimg, "affine")
if has_iter and not any([is_str, has_get_data, has_get_fdata]):
ref_niimg = ref_niimg[0]
is_str = isinstance(ref_niimg, str)
has_get_data = hasattr(ref_niimg, "get_data")
has_get_fdata = hasattr(ref_niimg, "get_fdata")
has_iter = hasattr(ref_niimg, "__iter__")
has_affine = hasattr(ref_niimg, "affine")
if not ((has_get_data or has_get_fdata) and has_affine):
if is_str:
ref_niimg = nibabel.load(ref_niimg)
else: