<commit_before>from __future__ import division, print_function, absolute_import

from glob import glob
from os.path import join, basename, splitext, dirname, isabs, exists
from os import makedirs

import nibabel as nib
import numpy as np

from dipy.segment.mask import median_otsu


def median_otsu_bet(input_file, out_dir, save_masked=False, median_radius=4,
                    numpass=4, autocrop=False, vol_idx=None, dilate=None):

    for fpath in glob(input_file):
        img = nib.load(fpath)
        volume = img.get_data()
        masked, mask = median_otsu(volume, median_radius, numpass, autocrop,
                                   vol_idx, dilate)

        fname, ext = splitext(basename(fpath))
        if(fname.endswith('.nii')):
            fname, _ = splitext(fname)
            ext = '.nii.gz'

        mask_fname = fname + '_mask' + ext

        if out_dir == '':
            out_dir_path = dirname(fpath)
        elif not isabs(out_dir):
            out_dir_path = join(dirname(fpath), out_dir)
            if not exists(out_dir_path):
                makedirs(out_dir_path)
        else:
            out_dir_path = out_dir

        mask_img = nib.Nifti1Image(mask.astype(np.float32), img.get_affine())
        mask_img.to_filename(join(out_dir_path, mask_fname))

        if save_masked:
            masked_fname = fname + '_masked' + ext
            masked_img = nib.Nifti1Image(masked, img.get_affine(), img.get_header())<commit_msg>Change output file name<commit_after>from __future__ import division, print_function, absolute_import

from glob import glob
from os.path import join, basename, splitext, dirname, isabs, exists
from os import makedirs

import nibabel as nib
import numpy as np

from dipy.segment.mask import median_otsu


def median_otsu_bet(input_file, out_dir, save_masked=False, median_radius=4,
                    numpass=4, autocrop=False, vol_idx=None, dilate=None):

    for fpath in glob(input_file):
        img = nib.load(fpath)
        volume = img.get_data()
        masked, mask = median_otsu(volume, median_radius, numpass, autocrop,
                                   vol_idx, dilate)

        fname, ext = splitext(basename(fpath))
        if(fname.endswith('.nii')):
            fname, _ = splitext(fname)
            ext = '.nii.gz'

        mask_fname = fname + '_mask' + ext

        if out_dir == '':
            out_dir_path = dirname(fpath)
        elif not isabs(out_dir):
            out_dir_path = join(dirname(fpath), out_dir)
            if not exists(out_dir_path):
                makedirs(out_dir_path)
        else:
            out_dir_path = out_dir

        mask_img = nib.Nifti1Image(mask.astype(np.float32), img.get_affine())
        mask_img.to_filename(join(out_dir_path, mask_fname))

        if save_masked:
            masked_fname = fname + '_bet' + ext
            masked_img = nib.Nifti1Image(masked, img.get_affine(), img.get_header())
{'fraction_non_alphanumeric': 0.09448818897637795, 'fraction_numerical': 0.004108182129407737, 'mean_word_length': 2.4785714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866460', 'n_tokens_mistral': 997, 'n_tokens_neox': 956, 'n_words': 210}