ascota_classification.texture¶
The texture module provides texture feature extraction and clustering
utilities for grouping pottery images by surface similarity.
Current functionality includes:
- luminance-aware texture summarization,
- feature extraction with scaling and PCA projection, and
- HDBSCAN-based clustering through low-level and high-level APIs.
Texture-based clustering for images with transparent backgrounds.
Clusters similar pottery by surface texture only (grayscale / luminance):
1. Luminance and alpha mask; crop to the opaque bounding box (no white compositing).
2. Local Binary Pattern (LBP) histograms at two radii + Gray-Level Co-occurrence Matrix
(GLCM) properties (mean over distances and angles).
3. Standardize features, reduce dimension with PCA.
4. Cluster with HDBSCAN (reuse cluster_images_hdbscan from color).
eom tends to merge clusters and often leaves fewer noise points; leaf extracts
finer structure but can label many points as noise unless min_samples is low (e.g. 1).
_luminance_from_rgb ¶
_luminance_from_rgb(rgb)
ITU-R BT.601 luma from uint8 RGB, shape (H, W).
Source code in src/ascota_classification/texture.py
57 58 59 60 61 62 63 | |
_prepare_rgb_and_mask ¶
_prepare_rgb_and_mask(
image, alpha_threshold=DEFAULT_ALPHA_THRESHOLD, resize_max=DEFAULT_RESIZE_MAX
)
RGB array and boolean mask of opaque pixels. No white compositing (texture-only).
Source code in src/ascota_classification/texture.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
_image_to_texture_summary ¶
_image_to_texture_summary(
image, alpha_threshold=DEFAULT_ALPHA_THRESHOLD, resize_max=DEFAULT_RESIZE_MAX
)
Fixed-length texture vector: LBP histograms (two scales) + pooled GLCM properties.
Uses luminance from RGB only; crops to opaque bounding box.
Source code in src/ascota_classification/texture.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
extract_texture_pca_features ¶
extract_texture_pca_features(
images,
pca_components=DEFAULT_PCA_COMPONENTS,
alpha_threshold=DEFAULT_ALPHA_THRESHOLD,
resize_max=DEFAULT_RESIZE_MAX,
)
Extract texture features (LBP + GLCM), standardize, and reduce with PCA.
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of (feature_matrix, pca, scaler): |
PCA
|
|
StandardScaler
|
|
Tuple[ndarray, PCA, StandardScaler]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If images list is empty. |
Source code in src/ascota_classification/texture.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
cluster_similar_images_by_texture ¶
cluster_similar_images_by_texture(
images,
min_cluster_size=DEFAULT_MIN_CLUSTER_SIZE,
min_samples=DEFAULT_MIN_SAMPLES,
cluster_selection_epsilon=DEFAULT_CLUSTER_SELECTION_EPSILON,
cluster_selection_method=DEFAULT_CLUSTER_SELECTION_METHOD,
pca_components=DEFAULT_PCA_COMPONENTS,
alpha_threshold=DEFAULT_ALPHA_THRESHOLD,
resize_max=DEFAULT_RESIZE_MAX,
return_pca_and_labels=False,
**hdbscan_kwargs
)
High-level pipeline: texture features + StandardScaler + PCA + HDBSCAN.
Returns:
| Type | Description |
|---|---|
Union[Tuple[List[List[int]], List[int]], Tuple[List[List[int]], List[int], PCA, ndarray, StandardScaler]]
|
If return_pca_and_labels is False: (clusters, noise_indices). |
Union[Tuple[List[List[int]], List[int]], Tuple[List[List[int]], List[int], PCA, ndarray, StandardScaler]]
|
If True: (clusters, noise_indices, pca, labels, scaler). |
Source code in src/ascota_classification/texture.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |