Skip to content
Snippets Groups Projects
Commit d5656cde authored by Constantin Pape's avatar Constantin Pape
Browse files

Add check for validation data

parent d9f61770
No related branches found
No related tags found
1 merge request!8Segmentation validation and correction
import h5py
from heimdall import view, to_source
def check_cell_evaluation():
from scripts.segmentation.validation.eval_cells import (eval_slice,
get_ignore_seg_ids,
get_bounding_box)
praw = '../../data'
pseg = '../../data'
pann = '../../data'
table_path = '../../data'
ignore_seg_ids = get_ignore_seg_ids(table_path)
with h5py.File(pseg, 'r') as fseg, h5py.File(pann, 'r') as fann:
ds_seg = fseg['t00000/s00/0/cells']
ds_ann = fann['xy/']
print("Run evaluation ...")
res, masks = eval_slice(ds_seg, ds_ann, ignore_seg_ids, min_radius=16,
return_maksks=True)
fm, fs = masks['false_merges'], masks['false_splits']
print()
print("Eval result")
print(res)
print()
print("Load raw data ...")
bb = get_bounding_box(ds_ann)
with h5py.File(praw, 'r') as f:
raw = f['t00000/s00/1/cells'][bb]
print("Load seg data ...")
seg = ds_seg[bb].squeeze()
view(to_source(raw, name='raw'), to_source(seg, name='seg'),
to_source(fm, name='merges'), to_source(fs, name='splits'))
# def check_nucleus_evaluation():
# eval_nuclei()
if __name__ == '__main__':
check_cell_evaluation()
......@@ -5,16 +5,22 @@ from elf.io import open_file, is_dataset
from .evaluate_annotations import evaluate_annotations, merge_evaluations
def eval_slice(ds_seg, ds_ann, ignore_seg_ids, min_radius):
ds_seg.n_threads = 8
ds_ann.n_threads = 8
attrs = ds_ann.attrs
def get_bounding_box(ds):
attrs = ds.attrs
start, stop = attrs['starts'], attrs['stops']
bb = tuple(slice(sta, sto) for sta, sto in zip(start, stop))
return bb
def eval_slice(ds_seg, ds_ann, ignore_seg_ids, min_radius,
return_masks=False):
ds_seg.n_threads = 8
ds_ann.n_threads = 8
bb = get_bounding_box(ds_ann)
annotations = ds_ann[:]
seg = ds_seg[bb].squeeze()
assert annotations.shape == seg.shape
seg_eval = vigra.analysis.labelImageWithBackground(seg)
......@@ -28,7 +34,8 @@ def eval_slice(ds_seg, ds_ann, ignore_seg_ids, min_radius):
bg_annotations = annotations == 3
return evaluate_annotations(seg_eval, fg_annotations, bg_annotations,
this_ignore_ids, min_radius=min_radius)
this_ignore_ids, min_radius=min_radius,
return_masks=return_masks)
def get_ignore_seg_ids(table_path, ignore_names=['cuticle', 'neuropil', 'yolk']):
......@@ -55,8 +62,11 @@ def eval_cells(seg_path, seg_key,
def visit_annotation(name, node):
nonlocal eval_res
if is_dataset(node):
print("Evaluating:", name)
res = eval_slice(ds_seg, node, ignore_seg_ids, min_radius)
eval_res = merge_evaluations(res, eval_res)
else:
print("Group:", name)
g.visititems(visit_annotation)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment