Implements functions for ground truth estimation from the annotations of multiple experts. Based on SimpleITK.
exp_dir = Path('gt_tmp')
url = 'https://github.com/matjesg/deepflash2/releases/download/sample_data/'
download_sample_data(url, 'wue1_cFOS_expert_segmentation_samples.zip', exp_dir , extract=True)
files=['0004_mask.png', '0001_mask.png']
experts = [f'expert_{i}' for i in range(1,6)]
Installing SimpleITK, which is not a dependency of deepflash2
.
import_sitk();
Simultaneous truth and performance level estimation (STAPLE)
The STAPLE algorithm considers a collection of segmentations and computes a probabilistic estimate of the true segmentation and a measure of the performance level represented by each segmentation.
Source: Warfield, Simon K., Kelly H. Zou, and William M. Wells. "Simultaneous truth and performance level estimation (STAPLE): an algorithm for the validation of image segmentation." IEEE transactions on medical imaging 23.7 (2004): 903-921
def staple(segmentations, foregroundValue = 1, threshold = 0.5):
'STAPLE: Simultaneous Truth and Performance Level Estimation with simple ITK'
sitk = import_sitk()
segmentations = [sitk.GetImageFromArray(x) for x in segmentations]
STAPLE_probabilities = sitk.STAPLE(segmentations)
STAPLE = STAPLE_probabilities > threshold
#STAPLE = sitk.GetArrayViewFromImage(STAPLE)
return sitk.GetArrayFromImage(STAPLE)
for f in files:
for i in range(3,7):
experts = [f'expert_{j}' for j in range(1,i)]
segmentations = [_read_msk(exp_dir/exp/f) for exp in experts]
out_staple = staple(segmentations)
out_staple_multi = staple_multi_label(segmentations)
test_eq(out_staple, out_staple_multi)
t = GTEstimator(exp_dir=exp_dir, config=Config(instance_segmentation_metrics=True));
t.show_data(files=files);
t.gt_estimation()
t.show_gt(files=files)
t.gt_estimation(method='majority_voting', save_dir=exp_dir/'mv_test')
t.show_gt(method='majority_voting', max_n=2)
shutil.rmtree(exp_dir)