Returns: ndarray: the visualized image of shape (H, W, 3) (RGB) in uint8 type. The shape is scaled w.r.t the input image using the given `scale` argument.
(self)
| 308 | self.fig.savefig(filepath) |
| 309 | |
| 310 | def get_image(self): |
| 311 | """ |
| 312 | Returns: |
| 313 | ndarray: |
| 314 | the visualized image of shape (H, W, 3) (RGB) in uint8 type. |
| 315 | The shape is scaled w.r.t the input image using the given `scale` argument. |
| 316 | """ |
| 317 | canvas = self.canvas |
| 318 | s, (width, height) = canvas.print_to_buffer() |
| 319 | # buf = io.BytesIO() # works for cairo backend |
| 320 | # canvas.print_rgba(buf) |
| 321 | # width, height = self.width, self.height |
| 322 | # s = buf.getvalue() |
| 323 | |
| 324 | buffer = np.frombuffer(s, dtype="uint8") |
| 325 | |
| 326 | img_rgba = buffer.reshape(height, width, 4) |
| 327 | rgb, alpha = np.split(img_rgba, [3], axis=2) |
| 328 | return rgb.astype("uint8") |
| 329 | |
| 330 | |
| 331 | class Visualizer: |
no outgoing calls
no test coverage detected