The Image object#
The Image class is essential for all image
operations and processing within this Toolbox. The class
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.
- class Image(image: Image | ndarray | None = None, colororder: str | dict | None = None, copy: bool = False, size: tuple | list | None = None, dtype: DTypeLike | None = None, name: str | None = None, id: int | None = None, domain=None, binary: bool = False, **kwargs)[source]#
Image attributes and datatype#
Image attributes#
Describe the attributes of an Image.
|
Readable representation of image parameters |
|
Single line summary of image parameters |
|
Coordinate of center pixel |
|
Coordinate of centre pixel as integer |
|
Coordinate of centre pixel |
|
Coordinate of centre pixel as integer |
|
Image height |
|
Set/get image name |
|
Number of pixels in image plane |
|
Image size |
|
Image width |
Predicates#
Test attributes of an Image.
|
Image has BGR color order? |
|
Image has bolean values? |
|
Image has color pixels? |
|
Image has floating point pixel values? |
|
Image has integer values? |
|
Image has RGB color order? |
Image coordinates#
Describe the pixel coordinates of an Image.
|
Test if coordinate lies within image |
|
Coordinate arrays for image |
|
Image maximum u-coordinate |
|
Linear span of image horizontally |
|
Image maximum v-coordinate |
|
Linear span of image vertically |
NumPy pixel data#
Return Image pixel data as a NumPy array.
|
Image as NumPy array |
|
Convert Image to NumPy array of specified type |
|
Image as NumPy array in BGR color order |
|
Number of image array dimensions |
|
Image as NumPy array in RGB color order |
|
Image shape |
|
Image as float NumPy array |
|
Image as integer NumPy array |
|
Convert image to a column view |
Getting and setting pixels#
Access individual pixels or groups of pixels.
|
Return pixel value or slice from image |
|
Return pixel value |
|
Return pixel values at locations specified by a mask |
Image datatype#
Describe or change the datatype of Image pixel values.
|
Cast image datatype |
|
Cast value to same type as image |
|
Datatype of image |
|
False value for logical image |
|
Fix bad values in image |
|
Convert value to the same type as image |
|
Maximum value of image datatype |
|
Minimum value of image datatype |
|
Number of Inf pixels in image |
|
Number of NaN pixels in image |
|
Convert image datatype |
|
True value for logical image |
Image processing#
Sub images#
Extract sub-images or planes from an Image instance.
|
Extract the blue plane of a color image |
|
Create image copy |
|
Extract the green plane of a color image |
|
Extract plane(s) from color image |
|
Extract the red plane of a color image |
|
Extract region of interest |
Color info#
Return information about the color planes of an Image instance.
|
Parse a color order specification |
|
Convert a color dictionary to a list of color plane names |
|
Convert a color dictionary to a color order string |
|
Set/get color order of image |
|
Parse a color order specification to a color dictionary |
|
Image color order as a string |
|
Number of color planes |
Color space and gamma#
Convert between color spaces and perform gamma encoding and decoding.
|
Create chromaticity image |
|
Colorize a greyscale image |
|
Transform a color image between color representations |
|
Gamma decoding |
|
Gamma encoding |
|
k-means color clustering |
|
Convert color image to monochrome |
Composition#
Combine multiple Image instances into a single Image instance.
|
Convert stereo images to an anaglyph image |
|
Image blending |
|
Horizontal concatenation of images |
|
Overlay two greyscale images in different colors |
|
Concatenation of image planes |
|
Interactive display of stereo image pair |
|
Tile images into a grid |
|
Vertical concatenation of images |
Monadic functions#
Operate elementwise on an Image instance and returns a new Image instance.
|
Absolute value of image |
|
Apply a function to an image |
|
Clip pixel values |
|
Invert image |
|
Apply lookup table |
|
Histogram normalisaton |
|
Square root of image |
|
Image normalisation |
|
Image threshold |
|
Adaptive threshold |
|
Interactive thresholding |
Dyadic functions#
Operate elementwise on two Image instances and return a new Image instance.
|
Apply a function to two images |
|
Pixel-wise image merge |
|
Paste an image into an image |
Linear filtering#
Linear filtering operations including convolution, corner and edge detection.
|
Canny edge detection |
|
Image convolution |
|
Compute horizontal and vertical gradients |
|
Harris corner strength image |
|
Pyramidal image decomposition |
|
Compute image scalespace sequence |
|
Smooth image |
Non-linear (morphological) filtering#
Variety of non-linear morphological operations.
|
Morphological closing |
|
Morphological dilation |
|
Distance transform |
|
Find end points on a binary skeleton image |
|
Morphological erosion |
|
Hit or miss transform |
|
Median filter |
|
Morphological neighbourhood processing |
|
Morphological opening |
|
Rank filter |
|
Morphological skeletonization |
|
Morphological skeletonization with animation |
|
Find triple points |
|
Generalized spatial operator |
|
Compute zero crossing |
Image labeling#
Binary, greyscale and color image segmentation using various algorithms.
|
Blob labelling |
|
Blob labelling using graph-based segmentation |
|
Blob labelling using MSER |
Image similarity#
Various scalar image similarity measures.
|
Normalised cross correlation |
|
Sum of absolute differences |
|
Locate template in image |
|
Sum of squared differences |
|
Zero-mean normalized cross correlation |
|
Zero-mean sum of absolute differences |
|
Zero-mean sum of squared differences |
Shape changing#
Changing the shape of an Image instance.
|
Decimate an image |
|
Dice an image into a grid of subimages |
|
Pad the edges of the image |
|
Replicate image pixels |
|
Automatic image trimming |
|
Scale an image |
|
Trim pixels from the edges of the image |
Image distortion#
Distorting the image within an Image instance.
|
Image warping |
|
Roll image by row or column |
|
Rotate an image |
|
Rotate a spherical image |
|
Undistort image |
|
Image warping |
|
Affine warp of image |
|
Perspective warp |
Multiview operations#
Stereo image processing, rectification, and display.
|
Refine disparity from disparity space image |
|
Create rectification homographies |
|
Stereo block matching |
|
Stereo semi-global block matching |
|
Simple stereo matching |
Operators#
Binary arithmetic and relational operators#
Image☆Image
Image☆ scalarscalar ☆
Image
The result is always an Image.
For the first case, the images must have:
the same shape,
the same width and height but can have different number of color planes. The image with one plane is broadcast across the color planes of the other image.
A scalar value is broadcast across the whole image.
Arithmetic and bitwise logical operations can be performed elementwise on:
|
Overloaded |
|
Overloaded |
|
Overloaded |
|
Overloaded |
|
Overloaded |
|
Overloaded |
|
Overloaded unary |
|
Overloaded |
|
Overloaded |
|
|
|
|
|
|
|
Overloaded |
|
|
|
|
|
Overloaded |
|
Overloaded |
|
Overloaded |
Logical operations can be performed elementwise on: Image ☆ Image.
The result is always an Image with boolean pixel values:
|
Overloaded |
|
Overloaded |
|
Overloaded |
|
Overloaded |
|
Overloaded |
|
Overloaded |
Inplace arithmetic operators#
Arithmetic and bitwise logical operations can be performed elementwise on:
Image☆=Image
Image☆= scalar
The result is always an Image. A scalar value is broadcast across the whole image.
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
|
Overloaded in-place |
Plane stacking operators#
Stacking operations can be performed on multiple Image instances.
A scalar value is broadcast across the whole image to create a new Image instance.
In place stacking allows for planes to be appended.
|
Overloaded in-place |
|
Overloaded |
Image statistics#
maxMaximum value of all pixels
meanMean value of all pixels
medianMedian value of all pixels
minMinimum value of all pixels
statsDisplay pixel value statistics
stdStandard deviation of all pixels
varVariance of all pixels
histImage histogram
Image feature extraction#
Whole image features#
Histograms#
|
Image histogram |
Image moments#
|
Hu image moment invariants |
|
Image moments |
|
Image moments |
|
Normalized central image moments |
|
Central image moments |
Other#
|
Find non-zero pixel values as 1D indices |
|
Find non-zero pixel values as 2D coordinates |
|
Otsu threshold selection |
|
Find local maxima in image |
|
Sum of all pixels |
Region features#
Find homogeneous regions, text or fiducual tags.
|
Find and describe blobs in image |
|
Find MSER features in image |
|
Optical character recognition |
Fiducial features#
|
Find fiducial markers in image |
Line features#
Find lines in an image.
|
Find Hough line features |
Point/corner features#
Find distincitive points in an image.
|
Find AKAZE features in image |
|
Find BRISK features in image |
|
Combination feature detector and descriptor |
|
Find Harris features in image |
|
Find ORB features in image |
|
Find SIFT features in image |
Image i/o#
File#
|
Get image EXIF metadata |
|
Read image from file |
|
Write image to file |
Graphical#
|
Display image |
|
Display image with pixel values |
Text#
|
Print image pixels in compact format |
|
Format several small images concatenated horizontally |
Constant images#
Create images that are constant, random, or have a simple geometric pattern.
|
Create chequerboard pattern |
|
Create image containing grid of circles |
|
Create image with all pixels having same value |
|
Create an image containing filled polygons |
|
Create image of linear ramps |
|
Create image with random pixel values |
|
Create image of sinusoidal intensity pattern |
|
Create image containing grid of squares |
|
Create a small image from text string |
|
Create image with zero value pixels |
Graphical annotation#
Render simple graphical annotations into an image. The equivalent functions plot_xxx
from SpatialMath Toolbox create graphical overlays rather than changing the the image data.
|
Draw box into image |
|
Draw circle into image |
|
Draw label box into image |
|
Draw line into image |
|
Draw a marker in image |
|
Draw text into image :param pos: text position (u,v) :type pos: array_like(2) :param text: text to draw :type text: str :param kwargs: parameters passed to |
Test images#
Sometimes, for pedagogy and unit tests, it is helpful to create, process and numerically display small example images.