Skip to content

Play with Images and Bounding Boxes

Chitra is an image utility class that can load image from filelike object, web url or numpy image. It offers drawing bounding box over the image.

# pip install -U chitra

from chitra.image import Chitra
import matplotlib.pyplot as plt

What can it do?

  • Load image from file, filelike object, web url, or numpy array
  • Plot image
  • Plot bounding boxes along with labels in no extra code.
  • Specify bounding box format:
    • Center(xywh): center x,y and height width of bbox
    • Corner(xyxy): xmin ymin and xmax ymax
  • Plot bounding box on image
  • Resize Bounding Boxes with image resize

Load image from web url and show

url = ""
image = Chitra(url)


You can cache the image downloaded from internet URL by passing cache=True in argument. Second call to the same URL will not download from internet, instead image will be loaded from the local cache dir.

# first call - image will be downloaded from internet and saved to local cache dir
image = Chitra(url, cache=True)

# second call - image will be loaded from local cached dir
image = Chitra(url, cache=True)

Plot bounding box and label for the handphone

box = [[600, 250, 900, 600.1]]
label = ['handphone']
image = Chitra(url, box, label)
image.image = image.image.convert('RGB')


Resize Image and Bounding at the same time

Chitra can rescale your bounding box automatically based on the new image size.

box = [[600, 250, 900, 600.1]]
label = ['handphone']
image = Chitra(url, box, label)
image.resize_image_with_bbox((224, 224))

Last update: November 26, 2021