Skip to content
Snippets Groups Projects
Commit b973846b authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Wrote comparison table, caught case where ilastik can label multiple fragments of an object

parent 9d49942a
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import h5py
import json
import numpy as np
import pandas as pd
import skimage
import uuid
import vigra
......@@ -149,6 +150,32 @@ def generate_ilastik_object_classifier(template_ilp, where: str, lane=0):
return new_ilp
def compare_object_maps(truth: GenericImageDataAccessor, inferred: GenericImageDataAccessor) -> pd.DataFrame:
assert truth.shape == inferred.shape
assert np.all((truth.data == 0) == (inferred.data == 0))
assert inferred.chroma == 1
labels = []
for zi in range(0, inferred.nz):
inf_img = inferred.data[:, :, :, zi]
unique = np.unique(inf_img)
assert unique[0] == 0
dd = {'zi': zi, 'truth_label': np.unique(truth.data[:, :, :, zi])[1], 'multiples': False}
if len(unique) == 1: # no object in frame
dd['inferred_label'] = unique[0]
elif len(unique) > 2: # multiple objects in frame, so mask out all but largest
ob_id = skimage.measure.label(inf_img)
pr = skimage.measure.regionprops_table(ob_id, properties=['label', 'area'])
mask = inf_img == pr['label'][pr['area'].argmax()]
dd['inferred_label'] = np.unique(mask * inf_img)[1]
dd['multiples'] = True
else: # exactly one unique object class in frame
dd['inferred_label'] = unique[1]
labels.append(dd)
return pd.DataFrame(labels)
if __name__ == '__main__':
root = Path('c:/Users/rhodes/projects/proj0011-plankton-seg/')
......@@ -172,7 +199,6 @@ if __name__ == '__main__':
# write comparison
train_labels = generate_file_accessor(where_patch_stack / 'zstack_train_label.tif')
write_accessor_data_to_file(
where_patch_stack / 'comp.tif',
InMemoryDataAccessor(result_acc.data == train_labels.data)
)
\ No newline at end of file
df_comp = compare_object_maps(train_labels, result_acc)
df_comp.to_csv(where_patch_stack / autonumber_new_file(where_patch_stack, 'comp', 'csv'), index=False)
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