Skip to content

Commit

Permalink
Update postprocessing (output settings, allow no marker)
Browse files Browse the repository at this point in the history
  • Loading branch information
jommarin committed Jan 24, 2024
1 parent 24992c1 commit b16d5e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 7 additions & 7 deletions deepliif/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,18 @@ def get_net_tiles(n):
raise Exception(f'inference() not implemented for model {opt.model}')


def postprocess(orig, images, tile_size, seg_thresh=150, size_thresh='default', marker_thresh='default', size_thresh_upper=None, opt=None):
if opt.model == 'DeepLIIF':
def postprocess(orig, images, tile_size, model, seg_thresh=150, size_thresh='default', marker_thresh='default', size_thresh_upper=None):
if model == 'DeepLIIF':
resolution = '40x' if tile_size > 384 else ('20x' if tile_size > 192 else '10x')
overlay, refined, scoring = compute_results(np.array(orig), np.array(images['Seg']),
np.array(images['Marker'].convert('L')), resolution,
seg_thresh, size_thresh, marker_thresh, size_thresh_upper)
np.array(images['Marker'].convert('L')) if 'Marker' in images else None,
resolution, seg_thresh, size_thresh, marker_thresh, size_thresh_upper)
processed_images = {}
processed_images['SegOverlaid'] = Image.fromarray(overlay)
processed_images['SegRefined'] = Image.fromarray(refined)
return processed_images, scoring

elif opt.model == 'DeepLIIFExt':
elif model == 'DeepLIIFExt':
resolution = '40x' if tile_size > 768 else ('20x' if tile_size > 384 else '10x')
processed_images = {}
scoring = {}
Expand All @@ -455,7 +455,7 @@ def postprocess(orig, images, tile_size, seg_thresh=150, size_thresh='default',
return processed_images, scoring

else:
raise Exception(f'postprocess() not implemented for model {opt.model}')
raise Exception(f'postprocess() not implemented for model {model}')


def infer_modalities(img, tile_size, model_dir, eager_mode=False,
Expand Down Expand Up @@ -489,7 +489,7 @@ def infer_modalities(img, tile_size, model_dir, eager_mode=False,
)

if not hasattr(opt,'seg_gen') or (hasattr(opt,'seg_gen') and opt.seg_gen): # the first condition accounts for old settings of deepliif; the second refers to deepliifext models
post_images, scoring = postprocess(img, images, tile_size, opt=opt)
post_images, scoring = postprocess(img, images, tile_size, opt.model)
images = {**images, **post_images}
return images, scoring
else:
Expand Down
11 changes: 9 additions & 2 deletions deepliif/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ def compute_results(orig, seg, marker, resolution=None, seg_thresh=150, size_thr

if size_thresh == 'default':
size_thresh = calc_default_size_thresh(mask, resolution)
if marker_thresh == 'default':
if marker_thresh is None:
marker_thresh = 0
marker = None
elif marker_thresh == 'default':
marker_thresh = calc_default_marker_thresh(marker)

counts = compute_cell_classification(mask, marker, size_thresh, marker_thresh, size_thresh_upper=None)
Expand All @@ -417,7 +420,11 @@ def compute_results(orig, seg, marker, resolution=None, seg_thresh=150, size_thr
'num_total': counts['num_total'],
'num_pos': counts['num_pos'],
'num_neg': counts['num_neg'],
'percent_pos': round(counts['num_pos'] / counts['num_total'] * 100, 1) if counts['num_pos'] > 0 else 0
'percent_pos': round(counts['num_pos'] / counts['num_total'] * 100, 1) if counts['num_pos'] > 0 else 0,
'prob_thresh': seg_thresh,
'size_thresh': size_thresh,
'size_thresh_upper': size_thresh_upper,
'marker_thresh': marker_thresh if marker is not None else None,
}

overlay = np.copy(orig)
Expand Down

0 comments on commit b16d5e0

Please sign in to comment.