Skip to content

Measure Image & Object Texture

Measure Image Texture and Measure Object Texture measure the texture of one channel with Haralick’s features: how the gray levels of pixel pairs a fixed distance apart go together. Contrast is high where neighbouring pixels differ a lot, the angular second moment where few pairs repeat over and over (smooth or regular), entropy where the pairs are all different. The two commands compute the same 13 features; Measure Image Texture over the whole image, Measure Object Texture for each object of a class. To get both, add both steps. The values are those of CellProfiler’s MeasureTexture (which uses mahotas), value for value.

A small image of gray levels 0-3: each pixel is paired with the one Scale pixels to its right (0°); the pairs are counted in both orders into the co-occurrence matrix, from which the 13 features are computed - the same for 45°, 90° and 135°

Both are measurement steps: they run once per image plane, after all tiles of the image are read and all objects are found.

ParameterDescription
IDThe step’s ID, unique in the project. It is given automatically - texture_01, … for Measure Image Texture, object_texture_01, … for Measure Object Texture - and starts the names of its values in the results.
ObjectsMeasure Object Texture only: the objects measured. It must be set; the step stops with an error otherwise.
ChannelThe channel measured.
Scale [px]How far apart the two pixels of a pair are, in pixels (1 to 1000, default 3) - about the size of the texture’s grain.
Gray levelsThe gray levels the 8-bit values are rescaled to (2 to 256, default 256). Fewer are faster and less noisy; more see finer differences.
DirectionsMean of the directions (default): one value per feature, the mean over 0°, 45°, 90° and 135°. Each direction: one value per feature and direction - four times as many values.

Each name ends with the channel and the scale, e.g. “Contrast (channel 0, scale 3)”. With Each direction the angle is added (“Contrast 45° (channel 0, scale 3)”). Both commands use the same names. None of them has a unit.

MeasurementRangeHigh when …
Angular second moment0 to 1few pairs repeat over and over: smooth or very regular.
Contrast≥ 0neighbouring pixels differ a lot.
Correlation-1 to 1the gray levels of a pair depend linearly on each other.
Variance≥ 0the gray levels spread widely.
Inverse difference moment0 to 1the pairs have (nearly) equal gray levels: homogeneous.
Sum average≥ 0the pairs are bright.
Sum variance≥ 0the brightness of the pairs varies a lot.
Sum entropy≥ 0the sums of the pairs are spread over many values.
Entropy≥ 0the pairs are all different: irregular, complex.
Difference variance≥ 0the differences of the pairs are unevenly distributed.
Difference entropy≥ 0the differences of the pairs are spread over many values.
Information measure of correlation 1-1 to 0(closer to -1) the two pixels of a pair depend on each other.
Information measure of correlation 20 to 1the two pixels of a pair depend on each other.

The channel, as it is loaded from the image, is first converted to 8 bits: its values, normalised to 0 to 1 by the bit depth’s maximum, times 255 (rounded as scikit-image’s img_as_ubyte does). So the result does not depend on the bit depth. With fewer than 256 Gray levels the 8-bit values are then rescaled to 0…L−10 \dots L-1. An RGB image is turned into its luminance first.

For each direction, every pixel is paired with the pixel Scale pixels away:

DirectionPartner
0°to the right
45°down and to the left (= up and right)
90°below
135°down and to the right

Each pair (i,j)(i, j) of gray levels is counted in both orders, so the matrix is symmetric. Divided by the number of counts, it gives the probabilities p(i,j)p(i, j). From it come the marginal px(i)=∑jp(i,j)p_x(i) = \sum_j p(i,j) (the same as pyp_y), its mean μ\mu and variance σ2\sigma^2, the distribution of the sums px+y(k)p_{x+y}(k) (k=i+jk = i + j) and of the differences px−y(k)p_{x-y}(k) (k=∣i−j∣k = |i - j|).

With log⁡\log to base 2:

ASM=∑i,jp(i,j)2Contrast=∑kk2 px−y(k)Correlation=∑i,ji j p(i,j)−μ2σ2Variance=σ2IDM=∑i,jp(i,j)1+(i−j)2Sum average=∑kk px+y(k)Sum variance=∑kk2px+y(k)−(Sum average)2Sum entropy=−∑kpx+y(k)log⁡px+y(k)Entropy (HXY)=−∑i,jp(i,j)log⁡p(i,j)Difference entropy=−∑kpx−y(k)log⁡px−y(k)\begin{aligned} \text{ASM} &= \textstyle\sum_{i,j} p(i,j)^2 & \text{Contrast} &= \textstyle\sum_k k^2 \, p_{x-y}(k) \\ \text{Correlation} &= \dfrac{\sum_{i,j} i\,j\,p(i,j) - \mu^2}{\sigma^2} & \text{Variance} &= \sigma^2 \\ \text{IDM} &= \textstyle\sum_{i,j} \dfrac{p(i,j)}{1 + (i-j)^2} & \text{Sum average} &= \textstyle\sum_k k \, p_{x+y}(k) \\ \text{Sum variance} &= \textstyle\sum_k k^2 p_{x+y}(k) - (\text{Sum average})^2 & \text{Sum entropy} &= -\textstyle\sum_k p_{x+y}(k) \log p_{x+y}(k) \\ \text{Entropy } (H_{XY}) &= -\textstyle\sum_{i,j} p(i,j) \log p(i,j) & \text{Difference entropy} &= -\textstyle\sum_k p_{x-y}(k) \log p_{x-y}(k) \end{aligned}

The Difference variance is the variance of the values px−y(0),…,px−y(n−1)p_{x-y}(0), \dots, p_{x-y}(n-1) themselves, as mahotas computes it. The information measures of correlation use HX=−∑ipx(i)log⁡px(i)H_X = -\sum_i p_x(i) \log p_x(i) and HXY1=−∑i,jp(i,j)log⁡(px(i) px(j))H_{XY1} = -\sum_{i,j} p(i,j) \log\big(p_x(i)\,p_x(j)\big):

IMC 1=HXY−HXY1HX,IMC 2=1−e−2 (2HX−HXY)\text{IMC 1} = \frac{H_{XY} - H_{XY1}}{H_X}, \qquad \text{IMC 2} = \sqrt{1 - e^{-2\,(2 H_X - H_{XY})}}

Where the variance is 0 (a uniform image), the correlation is 1.

  • Measure Image Texture: every pixel counts, dark background included. Pairs that cross a tile border are counted as well.
  • Measure Object Texture: only pixels of the object’s mask, and only pairs whose two pixels are both in the mask and not at gray level 0 (as CellProfiler, which sets the pixels outside the object to 0). An object too small to hold a pair in one of the directions - e.g. narrower than Scale - gets no values (CellProfiler stores 0).
  • Scale: about the size of the structures whose texture you want - a few pixels for fine speckles, larger for coarse patterns. For objects, keep it clearly smaller than the objects.
  • Gray levels: 256 keeps all detail but makes the matrix sparse and the features noisy on small objects; 8 to 64 levels are steadier and faster.
  • Directions: the mean is independent of the texture’s orientation. Use Each direction only when the orientation matters (e.g. aligned fibres).

The values of Measure Image Texture belong to the image plane; in the List view they are under Columns › Measurements, named “texture_01 · Contrast (channel 0, scale 3)”. With A row per: Images each image shows its own value; with A row per: Objects each object row shows the value of its image plane. The values of Measure Object Texture (“object_texture_01 · Contrast (channel 0, scale 3)”) are shown on each object’s row and are aggregated over the image’s objects with A row per: Images.

The export option Measurements - one row per value writes every value with one row per value - see Exporting Results. With Each direction, one step gives 52 values, so select the measurements you need in the export’s Measurements.