imgviz

raw JSON →
2.0.0 verified Fri May 01 auth: no python

Image Visualization Tools for segmentation masks, bounding boxes, depth maps, and more. Latest version 2.0.0 (released 2024) with breaking changes to parameter and class names. Requires Python >=3.10. Maintained irregularly by wkentaro.

pip install imgviz
error TypeError: label2rgb() got an unexpected keyword argument 'img'
cause Parameter renamed from 'img' to 'image' in v2.0.0.
fix
Use image=... instead of img=....
error ImportError: cannot import name 'Depth2RGB' from 'imgviz'
cause Class renamed to Depth2Rgb in v2.0.0.
fix
Use from imgviz import Depth2Rgb.
error FileNotFoundError: [Errno 2] No such file or directory: '...' (when using imread)
cause OpenCV and pyglet backends for I/O removed in v2.0.0. Default backend may be missing.
fix
Use imgviz.io.imread only with imageio backend (or install optional dependencies). Alternatively, use imageio directly.
breaking v2.0.0 renames many function parameters: `img` -> `image`, `src` -> `image`, `imgs` -> `images`, `aabb1`/`aabb2` -> `yx1`/`yx2`, `shape` -> `height`/`width`/`row`/`col`. Update all call sites.
fix Use new parameter names; e.g., imgviz.draw.rectangle(yx1=(10,20), yx2=(30,40))
breaking Classes `Depth2RGB` and `Nchannel2RGB` renamed to `Depth2Rgb` and `Nchannel2Rgb`.
fix Use new class names: from imgviz import Depth2Rgb, Nchannel2Rgb
deprecated `plot_trajectory()` function removed in v2.0.0 (no more matplotlib dependency).
fix Use alternative plotting libraries (e.g., matplotlib directly) if needed.
gotcha Python 3.9 support dropped in v1.8.0; Python 3.10 minimum required for v1.8.0+. v2.0.0 also requires Python >=3.10.
fix Upgrade to Python >=3.10.

Label-to-RGB conversion and saving.

import numpy as np
import imgviz

# Create a sample segmentation mask
mask = np.zeros((100, 100), dtype=np.int32)
mask[20:40, 30:70] = 1
mask[60:80, 10:90] = 2

# Convert label image to RGB visualization
rgb = imgviz.label2rgb(mask)

# Show or save
# import matplotlib.pyplot as plt
# plt.imshow(rgb)
# plt.show()

# Save an image with labels
imgviz.io.lblsave('output.png', rgb)