ImageCanvas

class ibb.widgets.ImageCanvas(**kwargs: Any)[source]

This widget is capable of displaying numpy array as images and draw polygons on them. It scales the images to fit in the view and ensures the polygons are scaled accordingly as well. It is also capable to provide hover/click statuses for the displayed polygons.

Parameters
  • enable_rect (Boolean) – Whether to enable the rectangle functionality; Default True

  • auto_clear (Boolean) – Whether to clear the polygons when drawing a new image; Default True

  • enlarge (Boolean) – Whether to enlarge an image to take up the most space in the canvas; Default True

  • color (String) – Default color to draw polygons; Default #1F77B4

  • alpha (String) – Default alpha fill value for the polygons; Default 00

  • size (Integer) – Default border thickness for the polygons; Default 2

  • hover_style (Dict) – Default hover style (can contain color,alpha and/or size properties); Default None

  • click_style (Dict) – Default click style (can contain color,alpha and/or size properties); Default None

image

Image data in HWC order. See ImageCanvas.validate_image() for more information

Type

numpy.ndarray

polygons

polygons to draw. See ImageCanvas.validate_polygons() for more information

Type

dict

clicked

Index of the clicked rectangle

Type

Integer

hovered

Index of the hovered rectangle

Type

Integer

save

Save image and polygons

Type

Bool

Examples

Warning

Note that the widgets are not responding as we do not have a python backend running!

[1]:
import numpy as np
import ipywidgets
import ibb
[2]:
widget = ibb.widgets.ImageCanvas()
widget
[2]:
[3]:
widget.image = np.random.rand(512, 512);
[4]:
widget.polygons = [
    {'coords': [[0, 0], [0, 100], [100, 100], [100, 0]]},
    {'coords': [[100, 100], [100, 500], [500, 500], [500, 100]], 'color': '#ff0000', 'size': 5},
]