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)
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)
if liver_file is not None: # load the image file liver, liver_np = load_image(liver_file) # check whether there is a liver segmentation or not. has_liver_segmented = np.sum(liver_np.astype(np.uint8)) > 0 else: has_liver_segmented = False # extract the spacing from the ablation file pixdim = ablation.header['pixdim'] spacing = (pixdim[1], pixdim[2], pixdim[3]) # compute the surface distances based on tumor and ablation segmentations surface_distance = compute_distances( mask_gt=tumor_np, mask_pred=ablation_np, exclusion_zone=liver_np if has_liver_segmented else None, spacing_mm=spacing, connectivity=1, crop=False) # call the surface distance extraction function if surface_distance['distances_gt_to_pred'].size > 0: # if surface distances returned are not empty non_ablated, insufficiently_ablated, completely_ablated = \ pm.plot_histogram_surface_distances(pat_name=patient_id, lesion_id=lesion_id, output_file=output_file_histogram, distance_map=surface_distance['distances_gt_to_pred'], title='Quantitative Ablation Margin', print_case_details=True) df = pd.DataFrame( data={ 'Patient': [patient_id] *