Imutils

Contours

imutils.contours.label_contour(image, c, i, color=(0, 255, 0), thickness=2)
imutils.contours.sort_contours(cnts, method='left-to-right')

Convenience

imutils.convenience.adjust_brightness_contrast(image, brightness=0.0, contrast=0.0)

Adjust the brightness and/or contrast of an image

Parameters:
  • image – OpenCV BGR image

  • contrast – Float, contrast adjustment with 0 meaning no change

  • brightness – Float, brightness adjustment with 0 meaning no change

imutils.convenience.auto_canny(image, sigma=0.33)
imutils.convenience.build_montages(image_list, image_shape, montage_shape)

author: Kyle Hounslow

Converts a list of single images into a list of ‘montage’ images of specified rows and columns. A new montage image is started once rows and columns of montage image is filled. Empty space of incomplete montage images are filled with black pixels ——————————————————————————————— :param image_list: python list of input images :param image_shape: tuple, size each image will be resized to for display (width, height) :param montage_shape: tuple, shape of image montage (width, height) :return: list of montage images in numpy array format ———————————————————————————————

example usage:

# load single image img = cv2.imread(‘lena.jpg’) # duplicate image 25 times num_imgs = 25 img_list = [] for i in xrange(num_imgs):

img_list.append(img)

# convert image list into a montage of 256x256 images tiled in a 5x5 montage montages = make_montages_of_images(img_list, (256, 256), (5, 5)) # iterate through montages and display for montage in montages:

cv2.imshow(‘montage image’, montage) cv2.waitKey(0)


imutils.convenience.check_opencv_version(major, lib=None)
imutils.convenience.get_opencv_major_version(lib=None)
imutils.convenience.grab_contours(cnts)
imutils.convenience.is_cv2(or_better=False)
imutils.convenience.is_cv3(or_better=False)
imutils.convenience.is_cv4(or_better=False)
imutils.convenience.opencv2matplotlib(image)
imutils.convenience.resize(image, width=None, height=None, inter=3)
imutils.convenience.rotate(image, angle, center=None, scale=1.0)
imutils.convenience.rotate_bound(image, angle)
imutils.convenience.skeletonize(image, size, structuring=0)
imutils.convenience.translate(image, x, y)
imutils.convenience.url_to_image(url, readFlag=1)

Encodigns

imutils.encodings.base64_decode_array(a, dtype)
imutils.encodings.base64_decode_image(a)
imutils.encodings.base64_encode_array(a)
imutils.encodings.base64_encode_image(a)

Meta

imutils.meta.find_function(name, pretty_print=True, module=None)

Object Detection

imutils.object_detection.non_max_suppression(boxes, probs=None, overlapThresh=0.3)

Paths

imutils.paths.list_files(basePath, validExts=None, contains=None)
imutils.paths.list_images(basePath, contains=None)

Perspective

Text

imutils.text.put_centered_text(img, text, font_face, font_scale, color, thickness=1, line_type=8)

Utility for drawing vertically & horizontally centered text with line breaks

Parameters:
  • img – Image.

  • text – Text string to be drawn.

  • font_face – Font type. One of FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN, FONT_HERSHEY_DUPLEX, FONT_HERSHEY_COMPLEX, FONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALL, FONT_HERSHEY_SCRIPT_SIMPLEX, or FONT_HERSHEY_SCRIPT_COMPLEX, where each of the font ID’s can be combined with FONT_ITALIC to get the slanted letters.

  • font_scale – Font scale factor that is multiplied by the font-specific base size.

  • color – Text color.

  • thickness – Thickness of the lines used to draw a text.

  • line_type – Line type. See the line for details.

Returns:

None; image is modified in place

imutils.text.put_text(img, text, org, font_face, font_scale, color, thickness=1, line_type=8, bottom_left_origin=False)

Utility for drawing text with line breaks

Parameters:
  • img – Image.

  • text – Text string to be drawn.

  • org – Bottom-left corner of the first line of the text string in the image.

  • font_face – Font type. One of FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN, FONT_HERSHEY_DUPLEX, FONT_HERSHEY_COMPLEX, FONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALL, FONT_HERSHEY_SCRIPT_SIMPLEX, or FONT_HERSHEY_SCRIPT_COMPLEX, where each of the font ID’s can be combined with FONT_ITALIC to get the slanted letters.

  • font_scale – Font scale factor that is multiplied by the font-specific base size.

  • color – Text color.

  • thickness – Thickness of the lines used to draw a text.

  • line_type – Line type. See the line for details.

  • bottom_left_origin – When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.

Returns:

None; image is modified in place