Skip to content

Commit

Permalink
Fix nibabel .get_data warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ofgulban committed Jul 12, 2022
1 parent 6c904a6 commit 2c6e781
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pydeface/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions pydeface/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2c6e781

Please sign in to comment.