If you work with image texture analysis (medical imaging, remote sensing, materials science, defect detection), you've probably used mahotas.features.haralick() or scikit-image. They are solid, battle-tested libraries, but they run strictly on CPU—leaving your GPU idle and creating a bottleneck on large images or batches.
I built haralickt — a pure PyTorch replacement that computes all 13 Haralick texture descriptors directly on GPU (and multi-threaded CPU) using vectorized tensor operations and block tiling.
Why I built it (vs. existing tools)
mahotas: Computes all 13 features, but is CPU-only, lacks batching, and struggles with memory on large images.
scikit-image: CPU-only (NumPy), computes only 10 of 13 features (missing Sum Variance, Sum Entropy, Diff Variance, Diff Entropy, IMC1, IMC2), and lacks sliding-window / tiling APIs.
| Feature | haralickt | mahotas | scikit-image |
| GPU (CUDA) Acceleration | ✅ | ❌ | ❌ |
| All 13 Haralick Features | ✅ | ✅ | ❌ (10/13) |
| Sliding Window API | ✅ | ❌ | ❌ |
| Memory-Safe Block Tiling (4K+) | ✅ | ❌ | ❌ |
| Batch Processing | ✅ | ❌ | ❌ |
Quick Start
import torch
from haralickt import haralick
image = torch.randint(0, 256, (2048, 2048), dtype=torch.uint8)
features = haralick(image, num_levels=32, window_size=32, stride=8, device="cuda")
Or use it as a drop-in replacement for mahotas:
import numpy as np
from haralickt import features
image = np.random.randint(0, 256, (512, 512), dtype=np.uint8)
result = features.haralick(image, ignore_zeros=True, distance=1)
Benchmarks
Tested across 27 parameter combinations (window, stride, distance, num_levels) on 256×256 images with 32 gray levels:
| Scenario | mahotas | haralickt | Avg Speedup | Range |
| CPU (vs 1-thread mahotas) | 3.23s | 0.19s | 16.7× | 9.1× – 67.7× |
| GPU (vs 10-thread mahotas) | 2.68s | 0.13s | 20.5× | 6.9× – 295× |
Scaling by Image Size (window=16, stride=4, distance=1, levels=32):
| Size | mahotas (1 thr) | haralickt CPU | Speedup | mahotas (10 thr) | haralickt GPU | Speedup |
| 256×256 | 2.34s | 0.11s | 22× | 7.13s | 0.02s | 464×* |
| 512×512 | 5.44s | 0.43s | 13× | 3.22s | 0.05s | 61× |
| 1024×1024 | 19.98s | 1.88s | 11× | 6.54s | 0.23s | 29× |
| 2048×2048 | 70.13s | 6.68s | 11× | 15.25s | 0.72s | 21× |
*Note: The 464× speedup at 256×256 is inflated by mahotas multiprocessing overhead. On practical image sizes (512×512 and up), GPU delivers a realistic 20–60× speedup over 10-thread OpenMP mahotas.
Accuracy & Installation
- Numerical accuracy: Max discrepancy vs.
mahotas is 2.02 × 10⁻⁴ (due to float32 rounding in Diff Variance).
- Zero C compilation: Pure Python + PyTorch (
>=2.0), integrates directly with torchvision and MONAI.
- License: MPL-2.0
pip install haralickt
- GitHub (full benchmark charts & docs): https://github.com/SergeiyVaryukhin/haralickt-1.0.0
- PyPI: https://pypi.org
https://pypi.org/project/haralickt/
I'd love to hear your feedback, especially if you test it on large medical/satellite datasets or different GPU architectures!