This page collects various things which contribute, all together, to tracing the picture of how to formalise images data into quantifiable entities, and the mathematics behind some building blocks of doing computer vision. An image is nothing else than a matrix of values, single numbers in the case of grayscale ones and arrays of 3 numbers in the case of colour images in something like the RGB space, for instance.
A pixel value is given in terms of colour or intensity. Intensity is used in grayscale, it identifies the brightness of pixels and has a value between 0 and 255. For colour you have, for example, the values RGB (a triple) for red, green and blue, each reporting their respective intensities.
In a 32-bit graphic system, 8 bits are used to encode each of the three colours (RGB) and 8 further bits are used for the alpha channel, representing transparency: specifies how colours should be merged when overlapped.
A colour space describes the organisation of colours, a colour model is a way to represent colours as tuples of numbers. For example, Adobe RGB and sRGB are two different colour spaces, both based on the RGB colour model.
There are five major colour models:
CIE (1931, was created by the International Commission on Illumination, or CIE, from its French name): was the first attempt to link the wavelengths (pure colours) to the colours as perceived by humans. It uses the tristimulus values: the human eye has three kinds of cone cells, each of which has the peak of sensitivity for light at a given wavelength, so three parameters can be used, corresponding to the levels of the stimuli to the three types of cells.
RGB (red, green, blue): describes what light produces a given colour. Several colour spaces can be derived from this model.
YUV (luma plus chroma): it is built with a luma (brightness, achromatic) value and two chroma (colour information) values. YPbPr is its scaled version and YCbCr is its scaled digital version.
HSV, also known as HSB (hue, saturation, value/brightness): is a coordinate transformation of RGB (a cube) into a cylindrical space. Note that there is also HSL (L for lightness), which is similar. The HSV space is a cylinder:. The HSV space has been designed to represent colour properties in a way that is more in adherence to the human eye perception and is particularly useful in cases where illumination matters. The hue of a colour is the base (dominant) colour that composes it, or better, the degree to which our colour is far away from the basic hues (yellow, orange, red, violet, blue, green); the saturation of a colour is its intensity; the value of a colour represents its lightness/darkness.
CMYK (cyan, magenta, yellow, key -black-): it is used in printing, describes what inks need to be used so that the reflected light produces the given colour.
Colour spaces are:
LMS (long/medium/short), where long, medium and short refer to the wavelengths of peak sensitivity of cone cells: L for long (in the blue), M for medium (in the green) and S for short (in the red);
XYZ (tristimulus): humans perceive light in the green (medium) part of the electromagnetic spectrum as brighter than those in the red (long) and the blue (short) parts of the spectrum. Y is the luminance; Z the blue stimulation; X is a linear combination of the cone responses. So, at fixed X, the plane XZ contains all the cromaticities at that luminance. The cromaticity is the quality of colour regardless of luminance and is given by hue and saturation. This colour space encodes all colours that a typical human (with no colour deficiencies) can see.
Note that we can pass from the LMS space to the XYZ one by virtue of a transformation, which surfaces the fact that Z is equivalent to S, Y is a linear combination of L and M, and X is a linear combination of all three.
Pixel connectivity is the way pixels relate to neighbours, and there's two ways we can define it:
4-line: each pixel is connected to all those which touch one of their edges
8-line: each pixels is connected to all those which touch their edges and corners
Image moments are weighted averages of the pixels' intensities. They share a similarity to the definition of moments in probability, where the intensity plays the role of the probability density function.
For a grayscale image a raw moment is defined as
whereis a cell of the image and I its intensity;gives the order of the moment
Central moments are
It can be derived that
Some interesting results are:
central moments are invariant with respect to translation;
the second order moments define the orientation of the image;
for an analogy to physics, the 0-th moment has the same role as the mass of the object, the first moments are analogous to the center of mass and the second moments to the moments of inertia;
if the intensity is considered as a density, so that , the first moments andare the mean values in each coordinate, the second moments are the variances of the horizontal and vertical projections,is their covariance.
Moments are used to calculate features of the objects displayed in an image. Let us refer here to a binary image (see page).
The area of an object is directly linked to the 0-th raw moment. In fact, the area is simply the sum of the 1's, that is, the total number of white pixels:
First moments: Center of mass
The center of mass is given by, in each coordinate, by
Second moments: Inertia tensor, orientation, roundness and eccentricity
In analogy to mechanical moments, the central second order image moments , andcontain terms in whichis multiplied by the square of the distance from the center of mass. They compose the inertia tensor of the rotation of the object around its center of gravity:
From this, several parameters can be derived.
The eigenvalues of J:
give the main inertial axes of the rotation, which correspond to the semi-major and semi-minor axes of the ellipse which can be used as an approximation of the object.
The orientation of the object-ellipse is the anglebetween the x axis and the axis around which the object can be rotated with minimal inertia (the direction of the major semi-axis a). It corresponds to the eigenvector with minimal eigenvalue:
The roundness is defined as
where p is the perimeter of the object and A its area. It is 1 for a circle and greater than 1 for other objects.
The eccentricity is defined as
Given, a function of a new image scaled by factor, so that, if we rescale in such a way thatand, we haveand , so
Setting the total area to 1, then, so. The scale invariant (invariant by both scale and translation) is
An image can be reconstructed from its moments, when known. Assuming that all moments of a functionand of orderare known up to order, it is possible to obtain function whose moments match those of the original function up to order:
Assuming that the image is a continuous function bounded as, , then
and substituting the expansion above gives a set of equations which can be solved for the in terms of.
The Sobel (or Sobel-Feldman) operator is an operator used as a filter to create an image with emphasised edges. It is a discrete differentiation operator: computes an approximation of the gradient of the image density function .
The algorithm consists in applying a convolution to the image with a filter in both directions. Two kernels, and, are convolved with the image matrix to calculate approximations of the derivative in the two directions:
The convolution is applied at each point of the image, so that the matrix convolved with the kernel is the matrix centered on the point under consideration.
andrepresent the change in theanddirections, respectively. They can both decomposed as the product of an averaging and a differentiation kernels, so that for instance
This means they compute the gradient with smoothing.
The gradient magnitude
is computed at each point of the image, as well as the gradient direction
M K Hu, Visual pattern recognition by moment invariants, IRE transactions on information theory, 8.2, 1962
I Sobel, An isotropic 3×3 image gradient operator, Machine Vision for three-dimensional Sciences, 1990