imgviz Documentation

Image Visualization Tools.

_images/getting_started.jpg

Installation

pip install imgviz

# there are optional dependencies like skimage, below installs all.
pip install imgviz[all]

Getting Started

_images/getting_started.jpg
#!/usr/bin/env python
# flake8: noqa

import os.path as osp

import matplotlib.pyplot as plt

here = osp.dirname(osp.abspath(__file__))  # NOQA

# -----------------------------------------------------------------------------
# GETTING_STARTED {{
import imgviz

# sample data of rgb, depth, class label and instance masks
data = imgviz.data.arc2017()

rgb = data["rgb"]
gray = imgviz.rgb2gray(rgb)

# colorize depth image with JET colormap
depth = data["depth"]
depthviz = imgviz.depth2rgb(depth, min_value=0.3, max_value=1)

# colorize label image
class_label = data["class_label"]
labelviz = imgviz.label2rgb(class_label, image=gray, label_names=data["class_names"], font_size=20)

# instance bboxes
bboxes = data["bboxes"].astype(int)
labels = data["labels"]
masks = data["masks"] == 1
captions = [data["class_names"][l] for l in labels]
maskviz = imgviz.instances2rgb(gray, masks=masks, labels=labels, captions=captions)

# tile instance masks
insviz = [(rgb * m[:, :, None])[b[0] : b[2], b[1] : b[3]] for b, m in zip(bboxes, masks)]
insviz = imgviz.tile(imgs=insviz, border=(255, 255, 255))
insviz = imgviz.resize(insviz, height=rgb.shape[0])

# tile visualization
tiled = imgviz.tile(
    [rgb, depthviz, labelviz, maskviz, insviz],
    shape=(1, 5),
    border=(255, 255, 255),
    border_width=5,
)
# }} GETTING_STARTED
# -----------------------------------------------------------------------------

out_file = osp.join(here, ".readme/getting_started.jpg")
imgviz.io.imsave(out_file, tiled)

img = imgviz.io.imread(out_file)
plt.imshow(img)
plt.axis("off")
plt.show()

API Reference

Functions

imgviz.asgray

Convert any array to gray image.

imgviz.gray2rgb

Covnert gray to rgb.

imgviz.rgb2gray

Covnert rgb to gray.

imgviz.rgb2rgba

Convert rgb to rgba.

imgviz.rgb2hsv

Convert rgb to hsv.

imgviz.rgba2rgb

Convert rgba to rgb.

imgviz.hsv2rgb

Convert hsv to rgb.

imgviz.depth2rgb

Convert depth to rgb.

imgviz.flow2rgb

Visualize optical flow.

imgviz.instances2rgb

Convert instances to rgb.

imgviz.label_colormap

Label colormap.

imgviz.label2rgb

Convert label to rgb.

imgviz.nchannel2rgb

Convert nchannel array to rgb by PCA.

imgviz.plot_trajectory

Plot the trajectory using transform matrices

imgviz.centerize

Centerize image for specified image size

imgviz.normalize

Normalize image.

imgviz.resize

Resize image.

imgviz.tile

Tile images.

Classes

imgviz.Depth2RGB

Convert depth array to rgb.

imgviz.Nchannel2RGB

Convert nchannel array to rgb by PCA.

Draw Module

imgviz.draw.circle

Draw circle on numpy array with Pillow.

imgviz.draw.rectangle

Draw rectangle on numpy array with Pillow.

imgviz.draw.star

Draw star on numpy array with Pillow.

imgviz.draw.text

Draw text on numpy array with Pillow.

imgviz.draw.text_in_rectangle

Draw text in a rectangle.

imgviz.draw.text_size

Get text size (height and width).

imgviz.draw.triangle

Draw triangle on numpy array with Pillow.

IO Module

imgviz.io.imread

Read image from file.

imgviz.io.imsave

Save image to file.

imgviz.io.cv_imshow

Show image with OpenCV.

imgviz.io.cv_waitkey

Wait key for the OpenCV window.

imgviz.io.pyplot_to_numpy

Convert pyplot state to numpy array.

imgviz.io.pyglet_imshow

Show image with pyglet.

imgviz.io.pyglet_run

Start pyglet mainloop.

Indices and tables