Differentiable GLRLM Calculation

GLRLM Calculation Animation
Figure 1. The differentiable GLRLM algorithm: (1) Decompose the image into gray-level masks; (2) Convolve each mask with [1,1] to detect run ends; (3) Remove the last element of each run to capture run lengths; and (4) Repeat until masks are empty and the final GLRLM is formed by removing redundancy (substracting neighboring columns).

Method Overview

To compute the Gray-Level Run Length Matrix (GLRLM) in a differentiable manner, we first decompose the grayscale image $\mu(x,y)$ into binary masks $B_{i}$ for each gray level using:

$$T_{i} = \frac{1}{1 + e^{-\alpha(\mu - g_{i})}} \quad \text{where} \quad \alpha = 100.$$

These masks $B_{i}$ smoothly approximate hard thresholding. For each mask $B_{i}$ and a run length $l$ along direction $\theta$, we compute the cross-correlation inline as $C_{i,l,\theta} = B_{i} \star \mathbf{1}_{l,\theta}$, generating a response map that sums over $l$ consecutive pixels.

Next, to compute the cumulative run count of runs of length $\geq l$, we apply another sigmoid (with $\beta = 10$) to threshold the cross-correlations:

$$R(i,\geq l \mid \theta) = \sum_{x,y} \left[ \frac{1}{1 + \exp(-\beta[C_{i,l-1,\theta} - (l-1) + 0.5])} - \frac{1}{1 + \exp(-\beta[C_{i,l,\theta} - l + 0.5])} \right].$$

Finally, the number of runs of exact length $l$ is obtained by subtracting cumulative counts:

$$R(i,l \mid \theta) = R(i,\geq l \mid \theta) - R(i,\geq (l+1) \mid \theta).$$

By making each step differentiable, this approach permits end-to-end training and backpropagation through the GLRLM feature extraction process.