LibXtract 1.6.0
Grid extraction functions

Functions

int xtract_grid_moments (const double *data, const int N, const void *argv, double *result)
 Extract the moments of a grid up to the third order.
int xtract_grid_central_moments (const double *data, const int N, const void *argv, double *result)
 Extract the central moments of a grid up to the third order: its moments with columns and rows numbered from the centroid of its values.
int xtract_normalised_moments (const double *data, const int N, const void *argv, double *result)
 Extract the normalised moments of a grid from its central moments: the central moments in a form that does not change when the grid is made larger or smaller.
int xtract_hu_moments (const double *data, const int N, const void *argv, double *result)
 Extract the seven Hu moments of a grid from its normalised moments: values that do not change when the grid is moved, made larger or smaller, or rotated.
int xtract_cooccurrence_matrix (const double *data, const int N, const void *argv, double *result)
 Extract the co-occurrence matrix of the levels of a grid: how often each pair of levels occurs a given step apart (Haralick 1973).
int xtract_cooccurrence_contrast (const double *data, const int N, const void *argv, double *result)
 Extract the contrast of a co-occurrence matrix: the mean square difference between the two levels of a pair (Haralick 1973).
int xtract_cooccurrence_correlation (const double *data, const int N, const void *argv, double *result)
 Extract the correlation of a co-occurrence matrix: the Pearson correlation coefficient of the level of the first element of a pair with the level of the second (Haralick 1973).
int xtract_angular_second_moment (const double *data, const int N, const void *argv, double *result)
 Extract the angular second moment of a co-occurrence matrix: the sum of the squares of its values (Haralick 1973).
int xtract_inverse_difference_moment (const double *data, const int N, const void *argv, double *result)
 Extract the inverse difference moment of a co-occurrence matrix: the mean over the pairs of 1 / (1 + the square of the difference between the two levels) (Haralick 1973).
int xtract_local_binary_patterns (const double *data, const int N, const void *argv, double *result)
 Extract the histogram of the rotation-invariant uniform local binary patterns of a grid: how its elements compare with the eight around them (Ojala 2002).

Detailed Description

Functions that extract a scalar, a vector or a matrix from a grid: values in rows of equal width, where the neighbours of a value in its row and its column carry meaning

Function Documentation

◆ xtract_angular_second_moment()

int xtract_angular_second_moment ( const double * data,
const int N,
const void * argv,
double * result )

Extract the angular second moment of a co-occurrence matrix: the sum of the squares of its values (Haralick 1973).

Parameters
*dataa pointer to the first element in an array of doubles comprising the levels * levels values of a co-occurrence matrix as xtract_cooccurrence_matrix() gives it, or the sum of several such matrices: no value below 0. The values are divided by their sum
Nthe number of elements in the matrix, a perfect square
*argva pointer to NULL
*resultthe angular second moment, from 1 / N for pairs spread evenly over every pair of levels to 1 for pairs all at one pair of levels, or 0 with no result when the values do not sum to more than 0
Note
This is the quantity some libraries call energy and others call uniformity. A third group gives the name energy to its square root

◆ xtract_cooccurrence_contrast()

int xtract_cooccurrence_contrast ( const double * data,
const int N,
const void * argv,
double * result )

Extract the contrast of a co-occurrence matrix: the mean square difference between the two levels of a pair (Haralick 1973).

Parameters
*dataa pointer to the first element in an array of doubles comprising the levels * levels values of a co-occurrence matrix as xtract_cooccurrence_matrix() gives it, or the sum of several such matrices: no value below 0. The values are divided by their sum
Nthe number of elements in the matrix, a perfect square
*argva pointer to NULL
*resultthe contrast, 0 when the two elements of every pair are at the same level, or 0 with no result when the values do not sum to more than 0

◆ xtract_cooccurrence_correlation()

int xtract_cooccurrence_correlation ( const double * data,
const int N,
const void * argv,
double * result )

Extract the correlation of a co-occurrence matrix: the Pearson correlation coefficient of the level of the first element of a pair with the level of the second (Haralick 1973).

Parameters
*dataa pointer to the first element in an array of doubles comprising the levels * levels values of a co-occurrence matrix as xtract_cooccurrence_matrix() gives it, or the sum of several such matrices: no value below 0. The values are divided by their sum
Nthe number of elements in the matrix, a perfect square
*argva pointer to NULL
*resultthe correlation, from -1 to 1, or 0 with no result when the first elements or the second elements are all at one level, or when the values do not sum to more than 0

◆ xtract_cooccurrence_matrix()

int xtract_cooccurrence_matrix ( const double * data,
const int N,
const void * argv,
double * result )

Extract the co-occurrence matrix of the levels of a grid: how often each pair of levels occurs a given step apart (Haralick 1973).

Parameters
*dataa pointer to the first element in an array of doubles comprising the rows of a grid, one after another, each element a whole number from 0 to one less than the number of levels, as xtract_quantise() gives them
Nthe number of elements in the grid, at least 1 and a multiple of the width
*argva pointer to an array of five ints: the width of the grid, from 1 to N; the number of levels, from 1 to 46340; the column offset and the row offset of the second element of a pair from the first, each positive, negative or zero; and 1 to count every pair in both orders, which makes the matrix symmetric, or 0 to count it once
*resulta pointer to an array of doubles holding a square matrix with one row and one column per level: at index i * levels + j the fraction of the pairs in which the first element is at level i and the second, at the offset from it, is at level j. The matrix sums to 1. It is zeroed with no result when the offset is too large for the grid to hold a pair, and not written when an element is not a whole number or is outside the levels, which is an argument error
Note
xtract_spectral_entropy() with this matrix as its *data gives the entropy of the pairs, from 0 for pairs all at one pair of levels to 1 for pairs spread evenly over every pair

◆ xtract_grid_central_moments()

int xtract_grid_central_moments ( const double * data,
const int N,
const void * argv,
double * result )

Extract the central moments of a grid up to the third order: its moments with columns and rows numbered from the centroid of its values.

Parameters
*dataa pointer to the first element in an array of doubles comprising the rows of a grid, one after another: the element in column x of row y at index y * width + x
Nthe number of elements in the grid, at least 1 and a multiple of the width
*argva pointer to an int, the width of the grid: the number of elements in each row, from 1 to N
*resulta pointer to an array of 8 doubles: the central moments mu00, mu20, mu11, mu02, mu30, mu21, mu12 and mu03 in that order. Each is the sum over the grid of every element multiplied by its column distance from the centroid to the power of the first digit and its row distance to the power of the second, which makes mu00 the sum of the elements. They do not change when the values move to another place in the grid. The array is zeroed with no result when the elements sum to zero, which leaves the centroid undefined

◆ xtract_grid_moments()

int xtract_grid_moments ( const double * data,
const int N,
const void * argv,
double * result )

Extract the moments of a grid up to the third order.

Parameters
*dataa pointer to the first element in an array of doubles comprising the rows of a grid, one after another: the element in column x of row y at index y * width + x
Nthe number of elements in the grid, at least 1 and a multiple of the width
*argva pointer to an int, the width of the grid: the number of elements in each row, from 1 to N
*resulta pointer to an array of 10 doubles: the moments m00, m10, m01, m20, m11, m02, m30, m21, m12 and m03 in that order. Each is the sum over the grid of every element multiplied by its column number to the power of the first digit and its row number to the power of the second, with columns and rows numbered from 0. m00 is the sum of the elements, and m10 / m00 and m01 / m00 are the column and the row of their centroid

◆ xtract_hu_moments()

int xtract_hu_moments ( const double * data,
const int N,
const void * argv,
double * result )

Extract the seven Hu moments of a grid from its normalised moments: values that do not change when the grid is moved, made larger or smaller, or rotated.

Parameters
*dataa pointer to the first element in an array of 7 doubles: the normalised moments of a grid as xtract_normalised_moments() gives them
Nthe number of elements in the array pointed to by *data, which must be 7
*argva pointer to NULL
*resulta pointer to an array of 7 doubles: the moments in the order of Hu (1962). The first six are the same for a grid and its mirror image, and the seventh changes sign

◆ xtract_inverse_difference_moment()

int xtract_inverse_difference_moment ( const double * data,
const int N,
const void * argv,
double * result )

Extract the inverse difference moment of a co-occurrence matrix: the mean over the pairs of 1 / (1 + the square of the difference between the two levels) (Haralick 1973).

Parameters
*dataa pointer to the first element in an array of doubles comprising the levels * levels values of a co-occurrence matrix as xtract_cooccurrence_matrix() gives it, or the sum of several such matrices: no value below 0. The values are divided by their sum
Nthe number of elements in the matrix, a perfect square
*argva pointer to NULL
*resultthe inverse difference moment, 1 when the two elements of every pair are at the same level and nearer 0 the further apart they are, or 0 with no result when the values do not sum to more than 0
Note
This is one of two quantities that libraries call homogeneity. The other divides by 1 plus the difference itself

◆ xtract_local_binary_patterns()

int xtract_local_binary_patterns ( const double * data,
const int N,
const void * argv,
double * result )

Extract the histogram of the rotation-invariant uniform local binary patterns of a grid: how its elements compare with the eight around them (Ojala 2002).

Parameters
*dataa pointer to the first element in an array of doubles comprising the rows of a grid, one after another: the element in column x of row y at index y * width + x
Nthe number of elements in the grid, at least 1 and a multiple of the width
*argva pointer to an int, the width of the grid: the number of elements in each row, from 1 to N
*resulta pointer to an array of 10 doubles that sum to 1: the fraction of the elements with a neighbour on every side that fall in each class. An element is compared with its eight neighbours in the order they lie around it. When the neighbours at or above the element form one unbroken run, or are none or all of the eight, its class is their number, from 0 to 8. Every other element is in class 9. The classes do not change when the grid is turned a quarter or mirrored. The array is zeroed with no result when the grid has fewer than three columns or three rows, which leaves no element with a neighbour on every side

◆ xtract_normalised_moments()

int xtract_normalised_moments ( const double * data,
const int N,
const void * argv,
double * result )

Extract the normalised moments of a grid from its central moments: the central moments in a form that does not change when the grid is made larger or smaller.

Parameters
*dataa pointer to the first element in an array of 8 doubles: the central moments of a grid as xtract_grid_central_moments() gives them
Nthe number of elements in the array pointed to by *data, which must be 8
*argva pointer to NULL
*resulta pointer to an array of 7 doubles: the normalised moments nu20, nu11, nu02, nu30, nu21, nu12 and nu03 in that order, each the central moment of the same digits divided by mu00 to the power of 1 plus half the sum of the digits. The array is zeroed with no result when mu00 is not above zero