-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
34 lines (22 loc) · 1.01 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
from skimage import measure
def plot_contours(masks, bg_image, ax, center_coordinates=None, level=0.5, cmap='gray', linewidth=1):
"""Plot the contours of the cell masks on the image.
Parameters:
masks -- boolean array of shape (num_cells, h, w)
bg_image -- (real) image to plot in the background
ax -- subplot object to plot on
center_coordinates -- array of shape (num_masks, 2) with the x/y coordinates of the instance centers
level -- value along which to find contours
cmap -- color map for background image
linewidth -- line width of contours
"""
num_cells = masks.shape[0]
ax.imshow(bg_image, cmap=cmap)
for i in range(num_cells):
contours = measure.find_contours(masks[i], level)
for n, contour in enumerate(contours):
ax.plot(contour[:, 1], contour[:, 0], linewidth=linewidth)
if center_coordinates is not None:
for x in center_coordinates:
ax.scatter(x[0], x[1], marker='x')