Skip to content

Commit

Permalink
Fixed output naming issue and added cost options
Browse files Browse the repository at this point in the history
  • Loading branch information
ofgulban committed Dec 9, 2017
1 parent 27f3ee7 commit bea538b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pydeface/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def main():
help="Apply the created face mask to other images. Can take multiple "
"arguments.")

parser.add_argument(
"--cost", metavar='mutualinfo', required=False, default='mutualinfo',
help="FSL-FLIRT cost function. Default is 'mutualinfo'.")

parser.add_argument(
"--template", metavar='path', required=False,
help=("Optional template image that will be used as the registration "
Expand Down Expand Up @@ -92,7 +96,7 @@ def main():

# register template to infile
flirt = fsl.FLIRT()
flirt.inputs.cost_func = 'mutualinfo'
flirt.inputs.cost_func = args.cost
flirt.inputs.in_file = template
flirt.inputs.out_matrix_file = tmpmat
flirt.inputs.out_file = tmpfile2
Expand All @@ -116,7 +120,7 @@ def main():
outfile_img = Nifti1Image(outdata, infile_img.get_affine(),
infile_img.get_header())
outfile_img.to_filename(outfile)
print('Defaced input saved as:\n %s' % outfile)
print("Defaced image saved as:\n %s" % outfile)

# apply mask to other given images
if args.applyto is not None:
Expand All @@ -126,7 +130,8 @@ def main():
outdata = applyfile_img.get_data() * tmpfile_img.get_data()
applyfile_img = Nifti1Image(outdata, applyfile_img.get_affine(),
applyfile_img.get_header())
outfile_img.to_filename(applyfile)
outfile = output_checks(applyfile)
applyfile_img.to_filename(outfile)
print(' %s' % applyfile)

if args.nocleanup:
Expand Down
6 changes: 4 additions & 2 deletions pydeface/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ def initial_checks(template=None, facemask=None):
return template, facemask


def output_checks(outfile, infile, force=False):
def output_checks(infile, outfile=None, force=False):
"""Determine output file name."""
if force is None:
force = False
if outfile is None:
outfile = infile.replace('.nii', '_defaced.nii')

if os.path.exists(outfile) and force:
print('Previous output will be overwritten.')
elif os.path.exists(outfile):
raise Exception("%s already exists. Remove it first or use '--force' "
"flag to overwrite." % outfile)
else:
outfile = infile.replace('.nii', '_defaced.nii')
pass
return outfile

0 comments on commit bea538b

Please sign in to comment.