def run_intensity_fcm(infile, outfolder):

    from intensity_normalization.normalize import fcm
    from intensity_normalization.utilities import io

    try:
        if not exists(join(outfolder, "Robex")):
            makedirs(join(outfolder, "Robex"))

        if not exists(join(outfolder, "wm_masks")):
            makedirs(join(outfolder, "wm_masks"))

        filename = infile.split(sep)[-1].split(".")[0]
        i = io.open_nii(infile)
        b_mask = io.open_nii(
            join(outfolder, "robex_masks", filename + "_mask.nii.gz"))
        wm_mask = fcm.find_tissue_mask(i, b_mask)
        normalized = fcm.fcm_normalize(i, wm_mask)
        io.save_nii(wm_mask,
                    join(outfolder, "wm_masks", filename + "_wmmask.nii.gz"))
        io.save_nii(normalized, join(outfolder, filename + "_fcm.nii.gz"))
        shutil.move(join(infile), join(outfolder, "Robex"))
    except:
        e = sys.exc_info()
        print("Error: ", str(e[0]))
        print("Error: ", str(e[1]))
        print("Error: executing fcm method")
        sys.exit(2)
Example #2
0
 def test_fcm_normalization(self):
     normalized = fcm.fcm_normalize(self.img,
                                    self.wm_mask,
                                    norm_value=self.norm_val)
     self.assertAlmostEqual(
         normalized.get_data()[self.wm_mask.get_data()].mean(),
         self.norm_val,
         places=3)
Example #3
0
def process(image_fn, brain_mask_fn, wm_mask_fn, output_dir, args, logger):
    img = io.open_nii(image_fn)
    dirname, base, _ = io.split_filename(image_fn)
    if output_dir is not None:
        dirname = output_dir
        if not os.path.exists(dirname):
            logger.info('Making output directory: {}'.format(dirname))
            os.mkdir(dirname)
    if brain_mask_fn is not None:
        mask = io.open_nii(brain_mask_fn)
        wm_mask = fcm.find_wm_mask(img, mask)
        outfile = os.path.join(dirname, base + '_wmmask.nii.gz')
        io.save_nii(wm_mask, outfile, is_nii=True)
    if wm_mask_fn is not None:
        wm_mask = io.open_nii(wm_mask_fn)
        normalized = fcm.fcm_normalize(img, wm_mask, args.norm_value)
        outfile = os.path.join(dirname, base + '_fcm.nii.gz')
        logger.info('Normalized image saved: {}'.format(outfile))
        io.save_nii(normalized, outfile, is_nii=True)