Пример #1
0
    def test_04_perfect_overlap_5mm_margin(self):
        _, tumor_np = niftireader.load_image(
            _get_file_name('T01', '04_perfect_overlap_5mm_margin', 'Tumor'))
        _, ablation_np = niftireader.load_image(
            _get_file_name('T01', '04_perfect_overlap_5mm_margin', 'Ablation'))
        distances = margin.compute_distances(tumor_np, ablation_np, None, 1)
        df = margin.summarize_surface_dists('T01', 'L01', distances)
        print(df)

        record = df.loc[(df['Patient'] == "T01")
                        & (df['Lesion'] == 'L01')].iloc[0]
        self.assertEqual(record["nr_voxels"], 222.0)
        self.assertAlmostEqual(record["min_distance"], 4.12, delta=0.01)
        self.assertAlmostEqual(record["max_distance"], 5.0, delta=0.01)
Пример #2
0
    def test_03_n5mm_margin_subcapsular(self):
        _, tumor_np = niftireader.load_image(
            _get_file_name('T02', '03_-5mm_margin_subcapsular', 'Tumor'))
        _, ablation_np = niftireader.load_image(
            _get_file_name('T02', '03_-5mm_margin_subcapsular', 'Ablation'))
        _, liver_np = niftireader.load_image(
            _get_file_name('T02', '03_-5mm_margin_subcapsular', 'Liver'))

        distances = margin.compute_distances(tumor_np, ablation_np, liver_np,
                                             1)
        df = margin.summarize_surface_dists('T02', 'L03', distances)
        print(df)

        record = df.loc[(df['Patient'] == "T02")
                        & (df['Lesion'] == 'L03')].iloc[0]
        self.assertEqual(record["nr_voxels"], 317.0)
        self.assertAlmostEqual(record["min_distance"], -5.09, delta=0.01)
        self.assertAlmostEqual(record["max_distance"], -2.23, delta=0.01)
        patient_id = 'Test'
    if lesion_id is None:
        lesion_id = 1
    if ablation_date is None:
        ablation_date = today.strftime("%d-%m-%Y")
    if output_file is None:
        csv_dir = 'surface_distances_csv'
        if not os.path.exists(csv_dir):
            os.mkdir(csv_dir)
        output_file = os.path.join(csv_dir, str(patient_id) + '_' + str(lesion_id) + '_surface_distances.xlsx')
    if dir_path is None:
        dir_path = 'figures'
        if not os.path.exists(dir_path):
            os.mkdir(dir_path)

    tumor, tumor_np = load_image(tumor_file)
    # check if there is actually a segmentation in the file
    has_tumor_segmented = np.sum(tumor_np.astype(np.uint8)) > 0
    if has_tumor_segmented is False:
        print('No tumor segmentation mask found in the file provided...program exiting')
        sys.exit()
    ablation, ablation_np = load_image(ablation_file)
    has_ablation_segmented = np.sum(ablation_np.astype(np.uint8)) > 0

    if has_ablation_segmented is False:
        print('No ablation segmentation mask found in the file provided...program exiting')
        sys.exit()

    if liver_file is not None:
        # load the image file
        liver, liver_np = load_image(liver_file)