The Image object for image operations and processing

The Image class is a core component of this Toolbox. It encapsulates a NumPy array that contains the pixel values of a greyscale or color image as a 2D or 3D array respectively. An Image instance has a very large number of methods that perform useful operations on an image and wrap low-level operations performed using NumPy or OpenCV.

Image attributes and datatype

Image attributes

Describe the attributes of an Image.

width

Image width

height

Image height

size

Image size

npixels

Number of pixels in image plane

name

Set/get image name

centre

Coordinate of centre pixel

centre_int

Coordinate of centre pixel as integer

center

Coordinate of center pixel

center_int

Coordinate of centre pixel as integer

__str__

Single line summary of image parameters

__repr__

Single line summary of image parameters

Predicates

Test attributes of an Image.

isfloat

Image has floating point pixel values?

isint

Image has integer values?

isbool

Image has bolean values?

iscolor

Image has color pixels?

isbgr

Image has BGR color order?

isrgb

Image has RGB color order?

Image coordinates

Describe the pixel coordinates of an Image.

umax

Image maximum u-coordinate

vmax

Image maximum v-coordinate

uspan

Linear span of image horizontally

vspan

Linear span of image vertically

meshgrid

Coordinate arrays for image

contains

Test if coordinate lies within image

NumPy pixel data

Return Image pixel data as a NumPy array.

A

Set/get the NumPy array containing pixel values

rgb

Image as NumPy array in RGB color order

bgr

Image as NumPy array in BGR color order

image

Image as NumPy array

to_int

Image as integer NumPy array

to_float

Image as float NumPy array

view1d

Convert image to a column view

shape

Image shape

ndim

Number of image array dimensions

Image datatype

Describe or change the datatype of Image pixel values.

isfloat

Image has floating point pixel values?

isint

Image has integer values?

isbool

Image has bolean values?

dtype

Datatype of image

to

Convert image datatype

astype

Cast image datatype

to_int

Image as integer NumPy array

to_float

Image as float NumPy array

cast

Cast value to same type as image

like

Convert value to the same type as image

minval

Minimum value of image datatype

maxval

Maximum value of image datatype

true

True value for logical image

false

False value for logical image

Image processing

Sub images

Extract sub-images or planes from an Image instance.

roi

Extract region of interest

plane

Extract plane(s) from color image

red

Extract the red plane of a color image

green

Extract the green plane of a color image

blue

Extract the blue plane of a color image

__getitem__

Return pixel value or slice from image

Color info

Return information about the color planes of an Image instance.

iscolor

Image has color pixels?

isbgr

Image has BGR color order?

isrgb

Image has RGB color order?

colororder

Set/get color order of image

colororder_str

Image color order as a string

colordict

Parse a color order specification

nplanes

Number of color planes

plane

Extract plane(s) from color image

Color space and gamma

Convert between color spaces and perform gamma encoding and decoding.

mono

Convert color image to monochrome

colorize

Colorize a greyscale image

chromaticity

Create chromaticity image

colorspace

Transform a color image between color representations

gamma_encode

Gamma encoding

gamma_decode

Gamma decoding

kmeans_color

k-means color clustering

Composition

Combine multiple Image instances into a single Image instance.

Hstack

Horizontal concatenation of images

Vstack

Vertical concatenation of images

Tile

Tile images into a grid

Overlay

Overlay two greyscale images in different colors

Monadic functions

Operate elementwise on an Image instance and returns a new Image instance.

abs

Absolute value of image

sqrt

Square root of image

LUT

Apply lookup table

apply

Apply a function to an image

clip

Clip pixel values

normhist

Histogram normalisaton

stretch

Image normalisation

threshold

Image threshold

threshold_interactive

Interactive thresholding

threshold_adaptive

Adaptive threshold

invert

Invert image

Dyadic functions

Operate elementwise on two Image instances and return a new Image instance.

apply2

Apply a function to two images

blend

Image blending

choose

Pixel-wise image merge

paste

Paste an image into an image

direction

Gradient direction

Linear filtering

Linear filtering operations including convolution, corner and edge detection.

convolve

Image convolution

smooth

Smooth image

gradients

Compute horizontal and vertical gradients

direction

Gradient direction

Harris_corner_strength

Harris corner strength image

scalespace

Compute image scalespace sequence

pyramid

Pyramidal image decomposition

canny

Canny edge detection

Non-linear (morphological) filtering

Variety of non-linear morphological operations.

window

Generalized spatial operator

zerocross

Compute zero crossing

rank

Rank filter

medianfilter

Median filter

distance_transform

Distance transform

erode

Morphological erosion

dilate

Morphological dilation

close

Morphological closing

open

Morphological opening

morph

Morphological neighbourhood processing

hitormiss

Hit or miss transform

thin

Morphological skeletonization

thin_animate

Morphological skeletonization with animation

endpoint

Find end points on a binary skeleton image

triplepoint

Find triple points

Image labeling

Binary, greyscale and color image segmentation using various algorithms.

labels_binary

Blob labelling

labels_MSER

Blob labelling using MSER

labels_graphseg

Blob labelling using graph-based segmentation

kmeans_color

k-means color clustering

Image similarity

Various scalar image similarity measures.

sad

Sum of absolute differences

ssd

Sum of squared differences

ncc

Normalised cross correlation

zsad

Zero-mean sum of absolute differences

zssd

Zero-mean sum of squared differences

zncc

Zero-mean normalized cross correlation

similarity

Locate template in image

Shape changing

Changing the shape of an Image instance.

trim

Trim pixels from the edges of the image

pad

Pad the edges of the image

decimate

Decimate an image

replicate

Replicate image pixels

roi

Extract region of interest

samesize

Automatic image trimming

scale

Scale an image

view1d

Convert image to a column view

Image distortion

Distorting the image within an Image instance.

roll

Roll image by row or column

rotate

Rotate an image

rotate_spherical

Rotate a spherical image

warp

Image warping

warp_affine

Affine warp of image

warp_perspective

Perspective warp

interp2d

Image warping

undistort

Undistort image

Multiview operations

Stereo image processing, rectification, and display.

stdisp

Interactive display of stereo image pair

stereo_simple

Simple stereo matching

DSI_refine

Refine disparity from disparity space image

stereo_BM

Stereo block matching

stereo_SGBM

Stereo semi-global block matching

rectify_homographies

Create rectification homographies

Binary operators

Arithmetic and logical operations can be performed elementwise on: ImageImage, Image ☆ scalar, scalar ☆ Image. The result is always an Image.

__add__

Overloaded + operator

__sub__

Overloaded - operator

__mul__

Overloaded * operator

__pow__

Overloaded ** operator

__sub__

Overloaded - operator

__truediv__

Overloaded / operator

__floordiv__

Overloaded // operator

__and__

Overloaded & operator

__or__

Overloaded | operator

__xor__

Overloaded ^ operator

__lshift__

Overloaded << operator

__rshift__

Overloaded >> operator

__eq__

Overloaded == operator

__ne__

Overloaded != operator

__gt__

Overloaded > operator

__ge__

Overloaded >= operator

__lt__

Overloaded < operator

__le__

Overloaded <= operator

Unary operators

Operations can be performed elementwise on an Image and the result is always an Image.

__minus__

Overloaded unary - operator

__invert__

Overloaded ~ operator

Image feature extraction

Whole image features

Histograms

hist

Image histogram

Statistical measures

mean

Mean value of all pixels

std

Standard deviation of all pixels

var

Variance of all pixels

median

Median value of all pixels

stats

Display pixel value statistics

Image moments

mpq

Image moments

npq

Normalized central image moments

upq

Central image moments

moments

Image moments

humoments

Hu image moment invariants

Other

sum

Sum of all pixels

nonzero

Find non-zero pixel values as 2D coordinates

flatnonzero

Find non-zero pixel values as 1D indices

peak2d

Find local maxima in image

otsu

Otsu threshold selection

Region features

Find homogeneous regions, text or fiducual tags.

blobs

Find and describe blobs in image

MSER

Find MSER features in image

ocr

Optical character recognition

fiducial

Find fiducial markers in image

Line features

Find lines in an image.

canny

Canny edge detection

Hough

Find Hough line features

Point/corner features

Find distincitive points in an image.

SIFT

Find SIFT features in image

ORB

Find ORB features in image

BRISK

Find BRISK features in image

AKAZE

Find AKAZE features in image

Harris

Find Harris features in image

ComboFeature

Combination feature detector and descriptor

Image i/o

File

Read

Read image from file

write

Write image to file

metadata

Get image EXIF metadata

Graphical

disp

Display image

showpixels

Display image with pixel values

anaglyph

Convert stereo images to an anaglyph image

stdisp

Interactive display of stereo image pair

Text

String

Create a small image from text string

print

Print image pixels in compact format

strhcat

Format several small images concatenated horizontally

Constant images

Create images that are constant, random, or have a simple geometric pattern.

Zeros

Create image with zero value pixels

Constant

Create image with all pixels having same value

String

Create a small image from text string

Random

Create image with random pixel values

Squares

Create image containing grid of squares

Circles

Create image containing grid of circles

Ramp

Create image of linear ramps

Sin

Create image of sinusoidal intensity pattern

Graphical annotation

Render simple graphical annotations into an image.

draw_line

Draw line into image

draw_circle

Draw circle into image

draw_box

Draw box into image

Test images

Sometimes it helpful to create, process and numerically display small example images. These functions can help with that

String

Create a small image from text string

print

Print image pixels in compact format

strhcat

Format several small images concatenated horizontally

showpixels

Display image with pixel values