Plots the PAF on top of the image. Args: image: Shape (height, width, channels). The image on which the model was run. paf: Shape (height, width, 2 * len(paf_graph)). The PAF output by the model. step: The step with which to plot the scoremaps. colors: The colorm
(
image: np.ndarray,
paf: np.ndarray,
step: int = 5,
colors: list | None = None,
)
| 95 | |
| 96 | |
| 97 | def visualize_paf( |
| 98 | image: np.ndarray, |
| 99 | paf: np.ndarray, |
| 100 | step: int = 5, |
| 101 | colors: list | None = None, |
| 102 | ) -> tuple[plt.Figure, plt.Axes]: |
| 103 | """Plots the PAF on top of the image. |
| 104 | |
| 105 | Args: |
| 106 | image: Shape (height, width, channels). The image on which the model was run. |
| 107 | paf: Shape (height, width, 2 * len(paf_graph)). The PAF output by the model. |
| 108 | step: The step with which to plot the scoremaps. |
| 109 | colors: The colormap to use. |
| 110 | |
| 111 | Returns: |
| 112 | The figure and axis on which the image PAF was plot. |
| 113 | """ |
| 114 | ny, nx = np.shape(image)[:2] |
| 115 | fig, ax = form_figure(nx, ny) |
| 116 | ax.imshow(image) |
| 117 | n_fields = paf.shape[2] |
| 118 | if colors is None: |
| 119 | colors = ["r"] * n_fields |
| 120 | for n in range(n_fields): |
| 121 | U = paf[:, :, n, 0] |
| 122 | V = paf[:, :, n, 1] |
| 123 | X, Y = np.meshgrid(np.arange(U.shape[1]), np.arange(U.shape[0])) |
| 124 | M = np.zeros(U.shape, dtype=bool) |
| 125 | M[U**2 + V**2 < 0.5 * 0.5**2] = True |
| 126 | U = np.ma.masked_array(U, mask=M) |
| 127 | V = np.ma.masked_array(V, mask=M) |
| 128 | ax.quiver( |
| 129 | X[::step, ::step], |
| 130 | Y[::step, ::step], |
| 131 | U[::step, ::step], |
| 132 | V[::step, ::step], |
| 133 | scale=50, |
| 134 | headaxislength=4, |
| 135 | alpha=1, |
| 136 | width=0.002, |
| 137 | color=colors[n], |
| 138 | angles="xy", |
| 139 | ) |
| 140 | return fig, ax |
| 141 | |
| 142 | |
| 143 | def generate_model_output_plots( |
no test coverage detected