From 2c6e78195bfc6e074303c5f513629b7c2c3eaf79 Mon Sep 17 00:00:00 2001 From: Omer Faruk Gulban Date: Tue, 12 Jul 2022 17:04:21 +0200 Subject: [PATCH] Fix nibabel `.get_data` warnings --- pydeface/__main__.py | 10 ++++++---- pydeface/utils.py | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pydeface/__main__.py b/pydeface/__main__.py index bb4e182..e9695da 100644 --- a/pydeface/__main__.py +++ b/pydeface/__main__.py @@ -99,12 +99,14 @@ def main(): print("Defacing mask also applied to:") for applyfile in args.applyto: applyfile_img = load(applyfile) + applyfile_data = np.asarray(applyfile_img.dataobj) + warped_mask_data = np.asarray(warped_mask_img.dataobj) try: - outdata = applyfile_img.get_data() * warped_mask_img.get_data() + outdata = applyfile_data * warped_mask_data except ValueError: - tmpdata = np.stack([warped_mask_img.get_data()] * - applyfile_img.get_data().shape[-1], axis=-1) - outdata = applyfile_img.get_data() * tmpdata + tmpdata = np.stack(warped_mask_data * applyfile_data.shape[-1], + axis=-1) + outdata = applyfile_data * tmpdata applyfile_img = Nifti1Image(outdata, applyfile_img.affine, applyfile_img.header) outfile = pdu.output_checks(applyfile, force=args.force) diff --git a/pydeface/utils.py b/pydeface/utils.py index 10e4fff..b99eb37 100644 --- a/pydeface/utils.py +++ b/pydeface/utils.py @@ -113,13 +113,14 @@ def deface_image(infile=None, outfile=None, facemask=None, # multiply mask by infile and save infile_img = load(infile) + infile_data = np.asarray(infile_img.dataobj) warped_mask_img = load(warped_mask) + warped_mask_data = np.asarray(warped_mask_img.dataobj) try: - outdata = infile_img.get_data().squeeze() * warped_mask_img.get_data() + outdata = infile_data.squeeze() * warped_mask_data except ValueError: - tmpdata = np.stack([warped_mask_img.get_data()] * - infile_img.get_data().shape[-1], axis=-1) - outdata = infile_img.get_data() * tmpdata + tmpdata = np.stack(warped_mask_data * infile_img.shape[-1], axis=-1) + outdata = infile_data * tmpdata masked_brain = Nifti1Image(outdata, infile_img.affine, infile_img.header) masked_brain.to_filename(outfile)