CutoutViewer¶
- class ibb.widgets.CutoutViewer(**kwargs: Any)[source]¶
This widget can visualize a brambox dataset as bounding boxes drawn on top of the images.
Its arguments work a lot likebrambox.util.BoxDrawer. The main difference withBramboxVieweris that each polygon is shown as a separate cutout.- Parameters
images (callable or dict-like object) – A way to get the image or path to the image from the image labels in the dataframe
boxes (pandas.DataFrame) – Bounding boxes to draw
pad (int, float or tuple of 2 int/float) – Padding to add around the width and height (see Note); Default 10
label (pandas.Series) – Label to write above the boxes; Default class_label (confidence)
color (pandas.Series) – Color to use for drawing; Default every class_label will get its own color, up to 10 labels
size (pandas.Series) – Thickness of the border of the bounding boxes; Default 3
alpha (pandas.Series) – Alpha fill value of the bounding boxes; Default 00
**kwargs (dict) – Extra keyword arguments that will be passed to
Viewer
Note
If the images argument is callable, the image or path to the image will be retrieved in the following way: >>> image = images(image_label)
Otherwise the image or path is retrieved as: >>> image = images[image_label]
Note
The padding property can be one of 4 possible types: - int : A fixed pixel padding is added to each side. - float : A fixed pixel padding is added to each side. The padding is computed as
pad*box_width. - (int, int) : Separate pixel padding for the width and height. - (float, float) : Separate pixel padding for the width and height. The padding is computed as(pad[0]*box_width, pad[1]*box_height).Note that the padding is clipped inside of the image boundaries.
Note
The label, color, size and alpha arguments can also be tacked on to the boxes dataframe as columns. They can also be a single value, which will then be used for each bounding box.
Basically, as long as you can assign the value as a new column to the dataframe, it will work.
Examples¶
Warning
Note that the widgets are not responding as we do not have a python backend running!
[1]:
import brambox as bb
import ibb
[2]:
# Load annotations
anno = bb.io.load('pandas', 'annotations.h5')
anno
[2]:
| image | class_label | id | x_top_left | y_top_left | width | height | occluded | truncated | lost | difficult | ignore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 000001 | dog | NaN | 48.0 | 240.0 | 147.0 | 131.0 | 0.0 | 1.0 | False | False | False |
| 1 | 000001 | person | NaN | 8.0 | 12.0 | 344.0 | 486.0 | 0.0 | 1.0 | False | False | False |
| 2 | 000002 | train | NaN | 139.0 | 200.0 | 68.0 | 101.0 | 0.0 | 0.0 | False | False | False |
| 3 | 000003 | sofa | NaN | 123.0 | 155.0 | 92.0 | 40.0 | 0.0 | 0.0 | False | False | False |
| 4 | 000003 | chair | NaN | 239.0 | 156.0 | 68.0 | 49.0 | 0.0 | 0.0 | False | False | False |
| 5 | 000004 | car | NaN | 13.0 | 311.0 | 71.0 | 51.0 | 0.0 | 0.0 | False | False | False |
| 6 | 000004 | car | NaN | 362.0 | 330.0 | 138.0 | 59.0 | 0.0 | 1.0 | False | False | False |
| 7 | 000004 | car | NaN | 235.0 | 328.0 | 99.0 | 47.0 | 0.0 | 0.0 | False | False | False |
| 8 | 000004 | car | NaN | 175.0 | 327.0 | 77.0 | 37.0 | 0.0 | 0.0 | False | False | False |
| 9 | 000004 | car | NaN | 139.0 | 320.0 | 50.0 | 39.0 | 0.0 | 0.0 | False | False | False |
| 10 | 000004 | car | NaN | 108.0 | 325.0 | 42.0 | 28.0 | 0.0 | 0.0 | False | False | False |
| 11 | 000004 | car | NaN | 84.0 | 323.0 | 37.0 | 27.0 | 0.0 | 0.0 | False | False | False |
[3]:
ibb.CutoutViewer(
# Dictionary or Function to map image column to image paths
lambda name: f'images/{name}.jpg',
anno,
)
[3]: