MCPcopy Create free account
hub / github.com/DeepLabCut/DeepLabCut / visualize_locrefs

Function visualize_locrefs

deeplabcut/core/visualization.py:52–94  ·  view source on GitHub ↗

Plots a scoremap and the corresponding location refinement field on an image. Args: image: An image as a numpy array of shape (h, w, channels) scmap: A scoremap of shape (h, w) locref_x: The x-coordinate of the location refinement field, of shape (h, w) locref_y:

(
    image: np.ndarray,
    scmap: np.ndarray,
    locref_x: np.ndarray,
    locref_y: np.ndarray,
    step: int = 5,
    zoom_width: int = 0,
)

Source from the content-addressed store, hash-verified

50
51
52def visualize_locrefs(
53 image: np.ndarray,
54 scmap: np.ndarray,
55 locref_x: np.ndarray,
56 locref_y: np.ndarray,
57 step: int = 5,
58 zoom_width: int = 0,
59) -> tuple[plt.Figure, plt.Axes]:
60 """Plots a scoremap and the corresponding location refinement field on an image.
61
62 Args:
63 image: An image as a numpy array of shape (h, w, channels)
64 scmap: A scoremap of shape (h, w)
65 locref_x: The x-coordinate of the location refinement field, of shape (h, w)
66 locref_y: The y-coordinate of the location refinement field, of shape (h, w)
67 step: The step with which to plot the location refinement field.
68 zoom_width: The zoom width with which to plot the scoremaps.
69
70 Returns:
71 The figure and axis on which the image scoremap and locref field were plot.
72 """
73 fig, ax = visualize_scoremaps(image, scmap)
74 X, Y = np.meshgrid(np.arange(locref_x.shape[1]), np.arange(locref_x.shape[0]))
75 M = np.zeros(locref_x.shape, dtype=bool)
76 M[scmap < 0.5] = True
77 U = np.ma.masked_array(locref_x, mask=M)
78 V = np.ma.masked_array(locref_y, mask=M)
79 ax.quiver(
80 X[::step, ::step],
81 Y[::step, ::step],
82 U[::step, ::step],
83 V[::step, ::step],
84 color="r",
85 units="x",
86 scale_units="xy",
87 scale=1,
88 angles="xy",
89 )
90 if zoom_width > 0:
91 maxloc = np.unravel_index(np.argmax(scmap), scmap.shape)
92 ax.set_xlim(maxloc[1] - zoom_width, maxloc[1] + zoom_width)
93 ax.set_ylim(maxloc[0] + zoom_width, maxloc[0] - zoom_width)
94 return fig, ax
95
96
97def visualize_paf(

Callers 2

extract_save_all_mapsFunction · 0.90

Calls 1

visualize_scoremapsFunction · 0.70

Tested by

no test coverage detected