Skip to content

Add GLCM texture metrics (#963)#973

Merged
brendancol merged 7 commits intomasterfrom
issue-963
Mar 5, 2026
Merged

Add GLCM texture metrics (#963)#973
brendancol merged 7 commits intomasterfrom
issue-963

Conversation

@brendancol
Copy link
Contributor

Summary

New glcm_texture() function in xrspatial/glcm.py, per #963.

Computes six Haralick GLCM metrics (contrast, dissimilarity, homogeneity, energy, correlation, entropy) over a sliding window. Pass a single metric name for a 2-D result, or a list for a 3-D result with a leading metric dimension.

Backends:

  • NumPy: Numba-JIT kernel
  • Dask+NumPy: global quantization, then per-metric map_overlap
  • CuPy / Dask+CuPy: CPU fallback via cupy.asnumpy

Parameters: window_size (odd, >= 3), levels (2-256), distance (pixel pair spacing), angle (0/45/90/135 or None to average all four).

Other changes:

  • 29 tests (validation, known values, NaN handling, edge cases, cross-backend)
  • API docs in docs/source/reference/focal.rst
  • User guide notebook (examples/user_guide/22_GLCM_Texture.ipynb)
  • README feature matrix row (CuPy/Dask+CuPy marked CPU-fallback)
  • Registered in __init__.py and .xrs accessor

Closes #963

Test plan

  • pytest xrspatial/tests/test_glcm.py -- 29 tests pass
  • Verify notebook renders correctly
  • GPU smoke test on a CUDA machine (CuPy fallback path)

New xrspatial.glcm module with glcm_texture() for computing Haralick
texture features (contrast, dissimilarity, homogeneity, energy,
correlation, entropy) over a sliding window.

Supports numpy, dask+numpy, cupy, and dask+cupy backends. Dask path
pre-quantizes globally for consistent gray-level mapping across chunks.
29 tests covering validation, quantization, known-value checks,
NaN handling, edge cases, all six metrics, angle averaging, and
cross-backend consistency (numpy vs dask, cupy, dask+cupy).
Add glcm_texture to the focal reference docs and to the README
feature matrix. CuPy/Dask+CuPy marked as CPU-fallback.
Demonstrates single/multi metric usage, angle effects, Dask support,
and parameter reference on a synthetic four-texture raster.
@brendancol brendancol added enhancement New feature or request focal tools Focal statistics and hotspot analysis labels Mar 5, 2026
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 5, 2026
Standalone script with a six-zone synthetic raster. Keyboard
controls cycle through metrics, window sizes, gray levels, and
angles. Clicking a pixel shows its local GLCM matrix and a bar
chart of all six Haralick feature values.
@brendancol brendancol merged commit 2dc6bba into master Mar 5, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request focal tools Focal statistics and hotspot analysis performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add GLCM texture metrics to focal module

1 participant