Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import label, zoom
from stardist.matching import matching
from stardist.plot import render_label, render_label_pred
np.random.seed(42)
def create_example():
rand_gt = np.random.uniform(0,1,(8,8))
rand_pred = rand_gt+.1*np.random.uniform(-1,1,(8,8))
y_true, _ = label(zoom(rand_gt, (32,32))>.7)
y_pred, _ = label(zoom(rand_pred, (32,32))>.7)
return y_true, y_pred
# create some example data
y_true, y_pred = create_example()
# Calculate the matching (with IoU threshold `thresh`) and all metrics
res = matching(y_true, y_pred, thresh=0.5)
print(res)
# plot the label masks
for i, (img,title) in enumerate(zip((render_label(y_true),
render_label(y_pred),
render_label_pred(y_true, y_pred)),
("True","Pred"," TP/FP/FN (green/red/blue)"))):
plt.subplot(1,3,i+1)
plt.imshow(img)
plt.axis("off")
plt.title(title, fontsize=8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment