Matching Algorithms
global_regression(input_images, output_images, *, calculation_dtype='float32', output_dtype=None, vector_mask=None, debug_logs=False, custom_nodata_value=None, image_parallel_workers=None, window_parallel_workers=None, window_size=None, save_as_cog=False, specify_model_images=None, custom_mean_factor=1.0, custom_std_factor=1.0, save_adjustments=None, load_adjustments=None)
¶
Performs global radiometric normalization across overlapping images using least squares regression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_images
|
(str | List[str], required)
|
Defines input files from a glob path, folder, or list of paths. Specify like: "/input/files/.tif", "/input/folder" (assumes .tif), ["/input/one.tif", "/input/two.tif"]. |
required |
output_images
|
(str | List[str], required)
|
Defines output files from a template path, folder, or list of paths (with the same length as the input). Specify like: "/input/files/$.tif", "/input/folder" (assumes $_Global.tif), ["/input/one.tif", "/input/two.tif"]. |
required |
calculation_dtype
|
str
|
Data type used for internal calculations. Defaults to "float32". |
'float32'
|
output_dtype
|
str | None
|
Data type for output rasters. Defaults to input image dtype. |
None
|
vector_mask
|
Tuple[Literal['include', 'exclude'], str, Optional[str]] | None
|
Mask to limit stats calculation to specific areas in the format of a tuple with two or three items: literal "include" or "exclude" the mask area, str path to the vector file, optional str of field name in vector file that includes (can be substring) input image name to filter geometry by. Loaded stats won't have this applied to them. The matching solution is still applied to these areas in the output. Defaults to None for no mask. |
None
|
debug_logs
|
bool
|
If True, prints debug information and constraint matrices. Defaults to False. |
False
|
custom_nodata_value
|
float | int | None
|
Overrides detected NoData value. Defaults to None. |
None
|
image_parallel_workers
|
Tuple[Literal["process", "thread"], Literal["cpu"] | int] | None = None
|
Parallelization strategy at the image level. Provide a tuple like ("process", "cpu") to use multiprocessing with all available cores. Threads are supported too. Set to None to disable. |
None
|
window_parallel_workers
|
Tuple[Literal["process"], Literal["cpu"] | int] | None = None
|
Parallelization strategy at the window level within each image. Same format as image_parallel_workers. Threads are not supported. Set to None to disable. |
None
|
window_size
|
int | Tuple[int, int] | Literal['internal'] | None
|
Tile size for reading and writing: int for square tiles, tuple for (width, height), "internal" to use raster's native tiling, or None for full image. "internal" enables efficient streaming from COGs. |
None
|
save_as_cog
|
bool
|
If True, saves output as a Cloud-Optimized GeoTIFF using proper band and block order. |
False
|
specify_model_images
|
Tuple[Literal['exclude', 'include'], List[str]] | None
|
First item in tuples sets weather to 'include' or 'exclude' the listed images from model building statistics. Second item is the list of image names (without their extension) to apply criteria to. For example, if this param is only set to 'include' one image, all other images will be matched to that one image. Defaults to no exclusion. |
None
|
custom_mean_factor
|
float
|
Weight for mean constraints in regression. Defaults to 1.0. |
1.0
|
custom_std_factor
|
float
|
Weight for standard deviation constraints in regression. Defaults to 1.0. |
1.0
|
save_adjustments
|
str | None
|
The output path of a .json file to save adjustments parameters. Defaults to not saving. |
None
|
load_adjustments
|
str | None
|
If set, loads saved whole and overlapping statistics only for images that exist in the .json file. Other images will still have their statistics calculated. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
list
|
List[str]: Paths to the globally adjusted output raster images. |
Source code in spectralmatch/match/global_regression.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 95 96 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 164 165 166 167 168 169 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 213 214 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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
local_block_adjustment(input_images, output_images, *, calculation_dtype='float32', output_dtype=None, vector_mask=None, debug_logs=False, custom_nodata_value=None, image_parallel_workers=None, window_parallel_workers=None, window_size=None, save_as_cog=False, number_of_blocks=100, alpha=1.0, correction_method='gamma', save_block_maps=None, load_block_maps=None, override_bounds_canvas_coords=None, block_valid_pixel_threshold=0.001)
¶
Performs local radiometric adjustment on a set of raster images using block-based statistics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_images
|
(str | List[str], required)
|
Defines input files from a glob path, folder, or list of paths. Specify like: "/input/files/.tif", "/input/folder" (assumes .tif), ["/input/one.tif", "/input/two.tif"]. |
required |
output_images
|
(str | List[str], required)
|
Defines output files from a template path, folder, or list of paths (with the same length as the input). Specify like: "/input/files/$.tif", "/input/folder" (assumes $_Local.tif), ["/input/one.tif", "/input/two.tif"]. |
required |
calculation_dtype
|
str
|
Precision for internal calculations. Defaults to "float32". |
'float32'
|
output_dtype
|
str | None
|
Data type for output rasters. Defaults to input image dtype. |
None
|
vector_mask
|
Tuple[Literal['include', 'exclude'], str, Optional[str]] | None
|
A mask limiting pixels to include when calculating stats for each block in the format of a tuple with two or three items: literal "include" or "exclude" the mask area, str path to the vector file, optional str of field name in vector file that includes (can be substring) input image name to filter geometry by. It is only applied when calculating local blocks, as the reference map is calculated as the mean of all local blocks. Loaded block maps won't have this applied unless it was used when calculating them. The matching solution is still applied to these areas in the output. Defaults to None for no mask. |
None
|
debug_logs
|
bool
|
If True, prints progress. Defaults to False. |
False
|
custom_nodata_value
|
float | int | None
|
Overrides detected NoData value. Defaults to None. |
None
|
image_parallel_workers
|
Tuple[Literal["process", "thread"], Literal["cpu"] | int] | None = None
|
Parallelization strategy at the image level. Provide a tuple like ("process", "cpu") to use multiprocessing with all available cores. Threads are supported too. Set to None to disable. |
None
|
window_parallel_workers
|
Tuple[Literal["process"], Literal["cpu"] | int] | None = None
|
Parallelization strategy at the window level within each image. Same format as image_parallel_workers. Threads are not supported. Set to None to disable. |
None
|
window_size
|
int | Tuple[int, int] | Literal['block'] | None
|
Tile size for processing: int for square tiles, (width, height) for custom size, or "block" to set as the size of the block map, None for full image. Defaults to None. |
None
|
save_as_cog
|
bool
|
If True, saves as COG. Defaults to False. |
False
|
number_of_blocks
|
int | tuple | Literal['coefficient_of_variation']
|
int as a target of blocks per image, tuple to set manually set total blocks width and height, coefficient_of_variation to find the number of blocks based on this metric. |
100
|
alpha
|
float
|
Blending factor between reference and local means. Defaults to 1.0. |
1.0
|
correction_method
|
Literal['gamma', 'linear']
|
Local correction method. Defaults to "gamma". |
'gamma'
|
save_block_maps
|
tuple(str, str) | None
|
If enabled, saves block maps for review, to resume processing later, or to add additional images to the reference map. - First str is the path to save the global block map. - Second str is the path to save the local block maps, which must include "$" which will be replaced my the image name (because there are multiple local maps). |
None
|
load_block_maps
|
Tuple[str, List[str]] | Tuple[str, None] | Tuple[None, List[str]] | None
|
Controls loading of precomputed block maps. Can be one of: - Tuple[str, List[str]]: Load both reference and local block maps. - Tuple[str, None]: Load only the reference block map. - Tuple[None, List[str]]: Load only the local block maps. - None: Do not load any block maps. This supports partial or full reuse of precomputed block maps: - Local block maps will still be computed for each input image that is not linked to a local block map by the images name being included in the local block maps name (file name). - The reference block map will only be calculated (mean of all local blocks) if not set. - The reference map defines the reference block statistics and the local maps define per-image local block statistics. - Both reference and local maps must have the same canvas extent and dimensions which will be used to set those values. |
None
|
override_bounds_canvas_coords
|
Tuple[float, float, float, float] | None
|
Manually set (min_x, min_y, max_x, max_y) bounds to override the computed/loaded canvas extent. If you wish to have a larger extent than the current images, you can manually set this, along with setting a fixed number of blocks, to anticipate images will expand beyond the current extent. |
None
|
block_valid_pixel_threshold
|
float
|
Minimum fraction of valid pixels required to include a block (0–1). |
0.001
|
Returns:
Type | Description |
---|---|
list
|
List[str]: Paths to the locally adjusted output raster images. |
Source code in spectralmatch/match/local_block_adjustment.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 95 96 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 164 165 166 167 168 169 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 213 214 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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|