nii_img = nii_obj.get_data()
        header = nii_obj.header
        affine = nii_obj.affine

        # reshape to account for implicit "1" channel
        nii_img = np.reshape(nii_img, nii_img.shape + (1, ))
        nii_img = pad_image(nii_img)

        # segment
        segmented_img = apply_model_single_input(nii_img, model)

        # save resultant image
        segmented_filename = os.path.join(SEG_DIR, filename)
        segmented_nii_obj = nib.Nifti1Image(segmented_img,
                                            affine=affine,
                                            header=header)
        nib.save(segmented_nii_obj, segmented_filename)

        # Reorient back to original before comparisons
        print("Reorienting...")
        utils.reorient(filename, DATA_DIR, SEG_DIR)

        # get probability volumes and threshold image
        print("Thresholding...")
        utils.threshold(filename, REORIENT_DIR, REORIENT_DIR, 0.5)

    if os.path.exists(TMPDIR):
        shutil.rmtree(TMPDIR)

    K.clear_session()
Ejemplo n.º 2
0
    # reshape to account for implicit "1" channel
    nii_img = np.reshape(nii_img, nii_img.shape + (1, ))

    # segment
    segmented_img = apply_model_single_input(nii_img, model)

    # save resultant image
    segmented_filename = os.path.join(SEG_DIR, filename)
    segmented_nii_obj = nib.Nifti1Image(segmented_img,
                                        affine=affine,
                                        header=header)
    nib.save(segmented_nii_obj, segmented_filename)

    # Reorient back to original before comparisons
    print("Reorienting...")
    utils.reorient(filename, src_dir, SEG_DIR)

    # get probability volumes and threshold image
    print("Thresholding...")
    utils.threshold(filename, REORIENT_DIR, REORIENT_DIR, 0.5)

    if results.INMASK:
        mask_src_dir, mask = os.path.split(results.INMASK)
        preprocess.preprocess(mask,
                              src_dir=mask_src_dir,
                              dst_dir=PREPROCESSING_DIR,
                              tmp_dir=TMPDIR,
                              verbose=0,
                              skullstrip_script_path=SKULLSTRIP_SCRIPT_PATH,
                              remove_tmp_files=True)