Convert a 1-channel matrix of intensities to an RGB image employing a colormap. This function requires matplotlib. See `matplotlib colormaps `_ for a list of available colormap. Args: intensity (np.ndarray):
(intensity, cmap='cubehelix', normalize=False)
| 323 | |
| 324 | |
| 325 | def intensity_to_rgb(intensity, cmap='cubehelix', normalize=False): |
| 326 | """ |
| 327 | Convert a 1-channel matrix of intensities to an RGB image employing a colormap. |
| 328 | This function requires matplotlib. See `matplotlib colormaps |
| 329 | <http://matplotlib.org/examples/color/colormaps_reference.html>`_ for a |
| 330 | list of available colormap. |
| 331 | |
| 332 | Args: |
| 333 | intensity (np.ndarray): array of intensities such as saliency. |
| 334 | cmap (str): name of the colormap to use. |
| 335 | normalize (bool): if True, will normalize the intensity so that it has |
| 336 | minimum 0 and maximum 1. |
| 337 | |
| 338 | Returns: |
| 339 | np.ndarray: an RGB float32 image in range [0, 255], a colored heatmap. |
| 340 | """ |
| 341 | assert intensity.ndim == 2, intensity.shape |
| 342 | intensity = intensity.astype("float") |
| 343 | |
| 344 | if normalize: |
| 345 | intensity -= intensity.min() |
| 346 | intensity /= intensity.max() |
| 347 | |
| 348 | cmap = plt.get_cmap(cmap) |
| 349 | intensity = cmap(intensity)[..., :3] |
| 350 | return intensity.astype('float32') * 255.0 |
| 351 | |
| 352 | |
| 353 | def draw_text(img, pos, text, color, font_scale=0.4): |