Pipeline

The pipeline runs steps in the order supplied. To use the footprint processing functions before generating seamlines, include them after the raster matching steps:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from spectralmatch import pipeline

result = pipeline(
    shared_input_images="matched_images",
    shared_output_image_path="mosaic.tif",
    steps=(
        "create_footprints",
        "postprocess_footprints",
        "voronoi_center_seamline",
        "mask",
        "merge",
    ),
    create_footprints_band=1,
    create_footprints_eight_connected=True,
    postprocess_footprints_edge_distance=800,
    postprocess_footprints_hole_to_hole_distance=800,
    postprocess_footprints_cut_width="maximum_inscribed_circle",
    postprocess_footprints_cut_method="corridor",
    postprocess_footprints_smoothing_radius=220,
    postprocess_footprints_simplify_tolerance=120,
    postprocess_footprints_simplify_area_weight=0.5,
    postprocess_footprints_area_rank=1,
)

Postprocessing requires a suitable projected CRS. Tune distances in that CRS's linear units for your imagery; the example values are starting points for the WorldView example. Postprocessing is opt-in. The default workflow still creates footprints automatically when Voronoi has no polygon input.

Footprint paths and layer names pass automatically from creation to postprocessing and then to either seamline method. Explicit *_input_polygons and *_input_layer options override these inputs. When supplying an external polygon path without a layer name, the source's default layer is used. Set the same *_image_field_name for footprint creation and the selected seamline method when using a custom field.

Replace voronoi_center_seamline with weighted_seamline and supply weighted_seamline_rank_function to use ranked seamlines. Fields referenced by the expression must exist in the input polygons; postprocessing preserves them. Existing polygons can enter through postprocess_footprints_input_polygons or the chosen seamline step's *_input_polygons option.

Each footprint step can also be the final step, in which case shared_output_image_path is its output .gpkg file. Intermediate footprint outputs appear in the result dictionary under create_footprints and postprocess_footprints. Both steps use the shared worker, backend, debugging, resume, and temporary-output cleanup settings.

Run the spectral matching workflow as an ordered pipeline.

steps defines the exact step order. Intermediate outputs are written inside the pipeline temp directory. The final step writes to shared_output_image_path:

  • If the final step writes multiple rasters, shared_output_image_path must be a folder, a template containing $, or a list of paths.
  • If the final step is merge with merge_rasters_output_tiles=True, shared_output_image_path must be a folder without $; the result's output is that folder.
  • If the final step writes a single raster or vector, it must be a single file path without $.

Step-specific options use the underlying function's types and defaults. Shared cache and worker settings additionally support "auto" and default to it; shared_window_size defaults to 1024. Required inputs for optional steps are required only when selecting those steps.

Select create_footprints followed by postprocess_footprints before either seamline step to prepare its polygons. These steps retain the current rasters for later masking and merging. Polygon paths and layer names flow between steps unless an explicit input overrides them. Postprocessing is opt-in because its distances require a suitable projected CRS and tuning for the imagery.

Parameters:

Name Type Description Default
shared_window_scales tuple[int, ...] | None

Overview factors shared by all steps with build_overviews enabled, default (2, 4, 8, 16, 32); None or an empty tuple disables overview creation for those steps.

(2, 4, 8, 16, 32)
shared_window_size WindowSize

Processing window size; for tiled merge, also the output tile width and height in pixels, default 1024.

1024
shared_image_threads AutoThreads

Workers across images in other steps and across output tiles in tiled merge; single-file merge does not use this setting.

'auto'
shared_concurrent_processing_backend ConcurrentProcessingBackend

Shared process_pool or dask backend; forwarded to merge only with merge_rasters_output_tiles=True.

'process_pool'
shared_dask_scheduler DaskScheduler

Shared Dask scheduler; forwarded to merge only with merge_rasters_output_tiles=True.

None
shared_resume_from_steps Literal['no', 'yes', 'validate']

Shared resume mode: "no" overwrites, "yes" skips existing outputs, and "validate" checks existing outputs before reuse; tiled merge applies this to existing tiles in the output folder.

'no'
global_regression_pif_method Literal['entire', 'flood_from_match_points']

PIF selection method, default "flood_from_match_points", matching Match.global_regression.

'flood_from_match_points'
global_regression_pif_max_samples int | None

Maximum number of PIF samples, default 10000; None disables the cap.

10000
global_regression_pif_min_samples int | None

Minimum number of PIF samples, default 10.

10
create_footprints_image_field_name str

Image identifier field for generated footprints, default "image"; use the same field name in the seamline step.

'image'
create_footprints_output_layer str

Output GeoPackage layer for generated footprints, default "footprints".

'footprints'
create_footprints_band int

One-based raster band whose validity mask defines the footprints, default 1.

1
create_footprints_eight_connected bool

Use eight-connected polygonization, default True; False uses four-connected polygonization.

True
postprocess_footprints_input_polygons str | None

Explicit input polygon path; None uses the preceding footprint step's output.

None
postprocess_footprints_input_layer str | None

Explicit input layer; None inherits the preceding footprint step's layer when using its polygons.

None
postprocess_footprints_output_layer str

Output GeoPackage layer for processed footprints, default "footprints".

'footprints'
postprocess_footprints_edge_distance float

Maximum hole-to-edge distance in projected CRS units, default 800; 0 disables only edge cuts.

800
postprocess_footprints_hole_to_hole_distance float

Maximum distance between original holes in the same polygon component, default 800; 0 disables only hole-pair cuts.

800
postprocess_footprints_relative_edge_distance float | None

Optional edge-only limit on distance divided by sqrt(hole_area / pi), default None.

None
postprocess_footprints_cut_width int | Literal['hole_size', 'maximum_inscribed_circle']

Positive integer width, "hole_size" for the largest diameter, or "maximum_inscribed_circle" (default) for the inscribed diameter. Applies to both cut types; pairs use the smaller width.

'maximum_inscribed_circle'
postprocess_footprints_cut_method Literal['corridor', 'buffer']

Hole cutting method, "corridor" (default) or "buffer".

'corridor'
postprocess_footprints_smoothing_radius float

Inward smoothing radius in projected CRS units, default 240; 0 disables smoothing.

240
postprocess_footprints_simplify_tolerance float

Maximum inward simplification deviation in projected CRS units, default 120; 0 disables simplification.

120
postprocess_footprints_simplify_area_weight float

Area retention weight in [0, 1], default 0.5.

0.5
postprocess_footprints_area_filter float | None

Optional minimum component area in squared CRS units, default None.

None
postprocess_footprints_area_rank int | None

Keep the largest N components for positive N or smallest abs(N) for negative N; 0 or None keeps all; default 1.

1
voronoi_center_seamline_input_polygons str | None

Explicit input polygon path; None uses the preceding footprint step's output or creates footprints from the current images if no footprint step has run.

None
voronoi_center_seamline_input_layer str | None

Explicit input layer; None inherits the preceding footprint step's layer when using its polygons.

None
voronoi_center_seamline_output_layer str

Output GeoPackage layer name for Voronoi seamlines; default "seamlines".

'seamlines'
weighted_seamline_input_polygons str | None

Explicit input polygon path; None uses the preceding footprint step's output. One of these sources is required for weighted_seamline.

None
weighted_seamline_input_layer str | None

Explicit input layer; None inherits the preceding footprint step's layer when using its polygons.

None
weighted_seamline_rank_function str | None

Ranking expression, required when steps includes weighted_seamline.

None
merge_rasters_output_tiles bool

Create GeoTIFF tiles with gdal_retile in shared_output_image_path instead of a single GeoTIFF, default False.

False
joint_coregistration_resolution Resolution

Shared pixel size strategy (highest, average, lowest), positive int or float pixel size in CRS units, or None to preserve native resolution.

None
joint_coregistration_tie_feature_method Literal['orb']

'orb', currently the only supported tie-point detector.

'orb'
joint_coregistration_tie_grid_spacing float

Positive CRS-unit distance between ORB search centers; default 500.0; independent of joint_coregistration_local_grid_spacing.

500.0
joint_coregistration_tie_search_radius str

Square ORB read-window half-width as a positive number followed by 'crs' or 'px'. Default '128px' uses the coarser input resolution, giving approximately 256-by-256-pixel windows before overlap clipping.

'128px'
joint_coregistration_tie_orb_max_features int

Positive int ORB detection cap per image per window; default 100.

100
joint_coregistration_tie_max_matches_per_window int | None

Positive int selected-match cap per search window per image pair; default 1; None keeps all surviving matches.

1
joint_coregistration_tie_maximum_displacement float | None

Positive CRS-unit distance limiting detected match displacement; None disables the limit.

None
joint_coregistration_tie_ransac_reprojection_threshold float | None

Positive CRS-unit inlier threshold; None uses three pixels at the coarser input resolution.

None
joint_coregistration_tie_robust_loss Literal['none', 'huber', 'soft_l1', 'cauchy']

'none', 'huber' (default), 'soft_l1', or 'cauchy'; downweights inconsistent ties in both alignment stages.

'huber'
joint_coregistration_tie_robust_loss_scale float | None

Positive CRS-unit distance for both alignment stages; None uses the median pair RANSAC threshold, or 1.0 without pairs.

None
joint_coregistration_tie_save_path str | None

str output path for selected tie-point JSON in original zero-based pixel coordinates; None disables saving.

None
joint_coregistration_tie_save_crs_path str | None

str vector output path such as 'ties.gpkg' or 'ties.geojson', or None; saves both selected points per tie in the original input CRS, linked by tie_id.

None
joint_coregistration_tie_load_path str | None

str selected tie-point JSON path or None; reuses saved pairs directly; a missing file warns and loads nothing.

None
joint_coregistration_global_image_movement_penalty_weights dict[str, float] | None

Ordered dict[str, positive float] of wcmatch.glob basename patterns; first match wins; unmatched images and None use 1; larger weights resist global movement.

None
joint_coregistration_global_tie_alignment_strength float | str

Number in [0, 1] for all images or JSON object string such as '{"base": 0, "*": 1}'; first matching basename rule wins; unmatched images use 1; scales solved global corrections.

1.0
joint_coregistration_local_image_movement_penalty_weights dict[str, float] | None

Ordered dict[str, positive float] of wcmatch.glob basename patterns; first match wins; unmatched images and None use 1; larger weights resist local deformation.

None
joint_coregistration_local_tie_alignment_strength float | str

Number in [0, 1] for all images or JSON object string such as '{"base": 0, "*": 1}'; first matching basename rule wins; unmatched images use 1; scales solved local displacements.

1.0
global_regression_load_adjustments str | None

str statistics JSON path or None; a missing file warns and computes fresh statistics.

None
global_regression_pif_load_ties str | None

str selected tie-point JSON path or None; a missing file warns and detects PIF seed matches normally.

None
local_block_adjustment_load_block_maps Tuple[str, List[str]] | Tuple[str, None] | Tuple[None, List[str]] | None

(reference_tif_or_None, list_of_local_tifs_or_None) or None; missing files warn and their maps are computed.

None
align_rasters_resolution Resolution

Shared pixel size strategy (highest, average, lowest), positive int or float pixel size in CRS units, or None to preserve native resolution.

None
merge_rasters_resolution Literal['highest', 'average', 'lowest'] | int | float

Merge resolution strategy (highest, average, lowest) or a positive int or float specifying square output pixels in CRS units for either merge mode; default highest.

'highest'
merge_rasters_overlap int

Overlap in pixels between output tiles, default 0; nonzero values require tiled merge and must be smaller than shared_window_size.

0
merge_rasters_build_overviews bool

Build overviews using shared_window_scales, default False; tiled merge creates pyramid tiles in numbered subfolders and requires consecutive powers of two starting at 2.

False
merge_rasters_resampling_method Literal['nearest', 'near', 'bilinear', 'cubic', 'cubicspline', 'lanczos']

Resampling for both merge modes: nearest (or near), bilinear, cubic, cubicspline, or lanczos, default nearest.

'nearest'
merge_rasters_custom_tiles_csv str | None

Optional .csv filename within the tile folder; GDAL writes a headerless, semicolon-delimited index with columns tilename;minx;maxx;miny;maxy in the output CRS, also in each pyramid subfolder; requires tiled merge.

None
merge_rasters_create_vrts str

VRT filename within the tile folder, default "MergedImage.vrt"; also creates and links pyramid VRTs as overviews; a custom name requires tiled merge.

'MergedImage.vrt'
Source code in spectralmatch/chain.py
 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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
def pipeline(
    shared_input_images: Universal.SearchFolderOrListFiles,
    shared_output_image_path: Universal.CreateInFolderOrListFiles,
    *,
    shared_temp_dir: str | None = None,
    delete_temp_dir: bool = True,
    delete_previous_step: bool = False,
    shared_resume_from_steps: Literal["no", "yes", "validate"] = "no",
    shared_debug_logs: Universal.DebugLogs = False,
    shared_cache: AutoCache = "auto",
    shared_custom_nodata_value: Universal.CustomNodataValue = None,
    shared_window_size: Universal.WindowSize = 1024,
    shared_window_scales: tuple[int, ...] | None = (2, 4, 8, 16, 32),
    shared_image_threads: AutoThreads = "auto",
    shared_io_threads: AutoThreads = "auto",
    shared_tile_threads: AutoThreads = "auto",
    shared_concurrent_processing_backend: Universal.ConcurrentProcessingBackend = "process_pool",
    shared_dask_scheduler: Universal.DaskScheduler = None,
    shared_calculation_dtype: Universal.CalculationDtype = "float32",
    shared_output_dtype: Universal.CustomOutputDtype = None,
    shared_save_as_cog: Universal.SaveAsCog = False,
    steps: list[PipelineStep] | tuple[PipelineStep, ...] = DEFAULT_PIPELINE_STEPS,
    joint_coregistration_tie_feature_method: Literal["orb"] = "orb",
    joint_coregistration_tie_grid_spacing: float = 500.0,
    joint_coregistration_tie_search_radius: str = "128px",
    joint_coregistration_tie_orb_max_features: int = 100,
    joint_coregistration_tie_max_matches_per_window: int | None = 1,
    joint_coregistration_tie_maximum_displacement: float | None = None,
    joint_coregistration_tie_ransac_reprojection_threshold: float | None = None,
    joint_coregistration_tie_robust_loss: Literal["none", "huber", "soft_l1", "cauchy"] = "huber",
    joint_coregistration_tie_robust_loss_scale: float | None = None,
    joint_coregistration_tie_save_path: str | None = None,
    joint_coregistration_tie_save_crs_path: str | None = None,
    joint_coregistration_tie_load_path: str | None = None,
    joint_coregistration_global_model: Literal["none", "translation", "similarity", "affine"] = "translation",
    joint_coregistration_global_image_movement_penalty_weights: dict[str, float] | None = None,
    joint_coregistration_global_tie_alignment_strength: float | str = 1.0,
    joint_coregistration_local_model: Literal["none", "bilinear", "piecewise_affine"] = "piecewise_affine",
    joint_coregistration_local_image_movement_penalty_weights: dict[str, float] | None = None,
    joint_coregistration_local_tie_alignment_strength: float | str = 1.0,
    joint_coregistration_local_grid_spacing: float = 500.0,
    joint_coregistration_local_smoothness_weight: float = 1.0,
    joint_coregistration_local_bending_weight: float = 1.0,
    joint_coregistration_local_anchor_falloff_distance: float = 500.0,
    joint_coregistration_resampling_method: Literal["nearest", "bilinear", "cubic", "lanczos"] = "bilinear",
    joint_coregistration_tap: bool = False,
    joint_coregistration_resolution: Universal.Resolution = None,
    joint_coregistration_build_overviews: bool = False,
    align_rasters_resampling_method: Literal["nearest", "bilinear", "cubic"] = "bilinear",
    align_rasters_tap: bool = False,
    align_rasters_resolution: Universal.Resolution = None,
    global_regression_vector_mask: Universal.VectorMask = None,
    global_regression_estimate_stats: bool = True,
    global_regression_specify_model_images: MatchValidation.SpecifyModelImages = None,
    global_regression_custom_mean_factor: float = 1.0,
    global_regression_custom_std_factor: float = 1.0,
    global_regression_save_adjustments: str | None = None,
    global_regression_load_adjustments: str | None = None,
    global_regression_pif_method: Literal["entire", "flood_from_match_points"] = "flood_from_match_points",
    global_regression_pif_red_band_index: int | None = None,
    global_regression_pif_nir_band_index: int | None = None,
    global_regression_pif_vegetation_threshold: float = 0.2,
    global_regression_pif_inz_threshold: float = 0.25,
    global_regression_pif_region_radius: int = 5,
    global_regression_pif_max_samples: int | None = 10000,
    global_regression_pif_min_samples: int | None = 10,
    global_regression_pif_feature_method: Literal["orb"] = "orb",
    global_regression_pif_load_ties: str | None = None,
    global_regression_pif_save_inz: str | None = None,
    global_regression_build_overviews: bool = False,
    local_block_adjustment_vector_mask: Universal.VectorMask = None,
    local_block_adjustment_number_of_blocks: int | Tuple[int, int] | Literal["coefficient_of_variation"] = 100,
    local_block_adjustment_alpha: float = 1.0,
    local_block_adjustment_correction_method: Literal["gamma", "linear", "offset"] = "offset",
    local_block_adjustment_save_block_maps: Tuple[str, str] | None = None,
    local_block_adjustment_load_block_maps: Tuple[str, List[str]] | Tuple[str, None] | Tuple[None, List[str]] | None = None,
    local_block_adjustment_override_bounds_canvas_coords: Tuple[float, float, float, float] | None = None,
    local_block_adjustment_build_overviews: bool = False,
    create_footprints_image_field_name: str = "image",
    create_footprints_output_layer: str = "footprints",
    create_footprints_band: int = 1,
    create_footprints_eight_connected: bool = True,
    postprocess_footprints_input_polygons: str | None = None,
    postprocess_footprints_input_layer: str | None = None,
    postprocess_footprints_output_layer: str = "footprints",
    postprocess_footprints_edge_distance: float = 800,
    postprocess_footprints_hole_to_hole_distance: float = 800,
    postprocess_footprints_relative_edge_distance: float | None = None,
    postprocess_footprints_cut_width: int | Literal["hole_size", "maximum_inscribed_circle"] = "maximum_inscribed_circle",
    postprocess_footprints_cut_method: Literal["corridor", "buffer"] = "corridor",
    postprocess_footprints_smoothing_radius: float = 240,
    postprocess_footprints_simplify_tolerance: float = 120,
    postprocess_footprints_simplify_area_weight: float = 0.5,
    postprocess_footprints_area_filter: float | None = None,
    postprocess_footprints_area_rank: int | None = 1,
    voronoi_center_seamline_aoi_path: str | None = None,
    voronoi_center_seamline_input_polygons: str | None = None,
    voronoi_center_seamline_input_layer: str | None = None,
    voronoi_center_seamline_output_layer: str = "seamlines",
    voronoi_center_seamline_image_field_name: str = "image",
    voronoi_center_seamline_min_point_spacing: float = 10,
    voronoi_center_seamline_min_cut_length: float = 0,
    voronoi_center_seamline_debug_vectors_path: str | None = None,
    weighted_seamline_input_polygons: str | None = None,
    weighted_seamline_rank_function: str | None = None,
    weighted_seamline_image_field_name: str = "image",
    weighted_seamline_input_layer: str | None = None,
    weighted_seamline_output_layer: str = "seamlines",
    weighted_seamline_rank_descending: bool = True,
    mask_rasters_vector_mask: Universal.VectorMask = None,
    mask_rasters_include_touched_pixels: bool = False,
    merge_rasters_output_tiles: bool = False,
    merge_rasters_resolution: Literal["highest", "average", "lowest"] | int | float = "highest",
    merge_rasters_overlap: int = 0,
    merge_rasters_build_overviews: bool = False,
    merge_rasters_resampling_method: Literal["nearest", "near", "bilinear", "cubic", "cubicspline", "lanczos"] = "nearest",
    merge_rasters_custom_tiles_csv: str | None = None,
    merge_rasters_create_vrts: str = "MergedImage.vrt",
) -> dict[str, Any]:
    """
    Run the spectral matching workflow as an ordered pipeline.

    ``steps`` defines the exact step order. Intermediate outputs are written inside the pipeline temp directory. The final step writes to ``shared_output_image_path``:

    - If the final step writes multiple rasters, ``shared_output_image_path`` must be a folder, a template containing ``$``, or a list of paths.
    - If the final step is merge with merge_rasters_output_tiles=True, ``shared_output_image_path`` must be a folder without ``$``; the result's output is that folder.
    - If the final step writes a single raster or vector, it must be a single file path without ``$``.

    Step-specific options use the underlying function's types and defaults. Shared cache and worker settings additionally support "auto" and default to it; shared_window_size defaults to 1024. Required inputs for optional steps are required only when selecting those steps.

    Select ``create_footprints`` followed by ``postprocess_footprints`` before either seamline step to prepare its polygons. These steps retain the current rasters for later masking and merging. Polygon paths and layer names flow between steps unless an explicit input overrides them. Postprocessing is opt-in because its distances require a suitable projected CRS and tuning for the imagery.

    Args:
        shared_window_scales: Overview factors shared by all steps with build_overviews enabled, default (2, 4, 8, 16, 32); None or an empty tuple disables overview creation for those steps.
        shared_window_size: Processing window size; for tiled merge, also the output tile width and height in pixels, default 1024.
        shared_image_threads: Workers across images in other steps and across output tiles in tiled merge; single-file merge does not use this setting.
        shared_concurrent_processing_backend: Shared process_pool or dask backend; forwarded to merge only with merge_rasters_output_tiles=True.
        shared_dask_scheduler: Shared Dask scheduler; forwarded to merge only with merge_rasters_output_tiles=True.
        shared_resume_from_steps: Shared resume mode: "no" overwrites, "yes" skips existing outputs, and "validate" checks existing outputs before reuse; tiled merge applies this to existing tiles in the output folder.
        global_regression_pif_method: PIF selection method, default "flood_from_match_points", matching Match.global_regression.
        global_regression_pif_max_samples: Maximum number of PIF samples, default 10000; None disables the cap.
        global_regression_pif_min_samples: Minimum number of PIF samples, default 10.
        create_footprints_image_field_name: Image identifier field for generated footprints, default "image"; use the same field name in the seamline step.
        create_footprints_output_layer: Output GeoPackage layer for generated footprints, default "footprints".
        create_footprints_band: One-based raster band whose validity mask defines the footprints, default 1.
        create_footprints_eight_connected: Use eight-connected polygonization, default True; False uses four-connected polygonization.
        postprocess_footprints_input_polygons: Explicit input polygon path; None uses the preceding footprint step's output.
        postprocess_footprints_input_layer: Explicit input layer; None inherits the preceding footprint step's layer when using its polygons.
        postprocess_footprints_output_layer: Output GeoPackage layer for processed footprints, default "footprints".
        postprocess_footprints_edge_distance: Maximum hole-to-edge distance in projected CRS units, default 800; 0 disables only edge cuts.
        postprocess_footprints_hole_to_hole_distance: Maximum distance between original holes in the same polygon component, default 800; 0 disables only hole-pair cuts.
        postprocess_footprints_relative_edge_distance: Optional edge-only limit on distance divided by sqrt(hole_area / pi), default None.
        postprocess_footprints_cut_width: Positive integer width, "hole_size" for the largest diameter, or "maximum_inscribed_circle" (default) for the inscribed diameter. Applies to both cut types; pairs use the smaller width.
        postprocess_footprints_cut_method: Hole cutting method, "corridor" (default) or "buffer".
        postprocess_footprints_smoothing_radius: Inward smoothing radius in projected CRS units, default 240; 0 disables smoothing.
        postprocess_footprints_simplify_tolerance: Maximum inward simplification deviation in projected CRS units, default 120; 0 disables simplification.
        postprocess_footprints_simplify_area_weight: Area retention weight in [0, 1], default 0.5.
        postprocess_footprints_area_filter: Optional minimum component area in squared CRS units, default None.
        postprocess_footprints_area_rank: Keep the largest N components for positive N or smallest abs(N) for negative N; 0 or None keeps all; default 1.
        voronoi_center_seamline_input_polygons: Explicit input polygon path; None uses the preceding footprint step's output or creates footprints from the current images if no footprint step has run.
        voronoi_center_seamline_input_layer: Explicit input layer; None inherits the preceding footprint step's layer when using its polygons.
        voronoi_center_seamline_output_layer: Output GeoPackage layer name for Voronoi seamlines; default "seamlines".
        weighted_seamline_input_polygons: Explicit input polygon path; None uses the preceding footprint step's output. One of these sources is required for weighted_seamline.
        weighted_seamline_input_layer: Explicit input layer; None inherits the preceding footprint step's layer when using its polygons.
        weighted_seamline_rank_function: Ranking expression, required when steps includes weighted_seamline.
        merge_rasters_output_tiles: Create GeoTIFF tiles with gdal_retile in shared_output_image_path instead of a single GeoTIFF, default False.
        joint_coregistration_resolution: Shared pixel size strategy (highest, average, lowest), positive int or float pixel size in CRS units, or None to preserve native resolution.
        joint_coregistration_tie_feature_method: 'orb', currently the only supported tie-point detector.
        joint_coregistration_tie_grid_spacing: Positive CRS-unit distance between ORB search centers; default 500.0; independent of joint_coregistration_local_grid_spacing.
        joint_coregistration_tie_search_radius: Square ORB read-window half-width as a positive number followed by 'crs' or 'px'. Default '128px' uses the coarser input resolution, giving approximately 256-by-256-pixel windows before overlap clipping.
        joint_coregistration_tie_orb_max_features: Positive int ORB detection cap per image per window; default 100.
        joint_coregistration_tie_max_matches_per_window: Positive int selected-match cap per search window per image pair; default 1; None keeps all surviving matches.
        joint_coregistration_tie_maximum_displacement: Positive CRS-unit distance limiting detected match displacement; None disables the limit.
        joint_coregistration_tie_ransac_reprojection_threshold: Positive CRS-unit inlier threshold; None uses three pixels at the coarser input resolution.
        joint_coregistration_tie_robust_loss: 'none', 'huber' (default), 'soft_l1', or 'cauchy'; downweights inconsistent ties in both alignment stages.
        joint_coregistration_tie_robust_loss_scale: Positive CRS-unit distance for both alignment stages; None uses the median pair RANSAC threshold, or 1.0 without pairs.
        joint_coregistration_tie_save_path: str output path for selected tie-point JSON in original zero-based pixel coordinates; None disables saving.
        joint_coregistration_tie_save_crs_path: str vector output path such as 'ties.gpkg' or 'ties.geojson', or None; saves both selected points per tie in the original input CRS, linked by tie_id.
        joint_coregistration_tie_load_path: str selected tie-point JSON path or None; reuses saved pairs directly; a missing file warns and loads nothing.
        joint_coregistration_global_image_movement_penalty_weights: Ordered dict[str, positive float] of wcmatch.glob basename patterns; first match wins; unmatched images and None use 1; larger weights resist global movement.
        joint_coregistration_global_tie_alignment_strength: Number in [0, 1] for all images or JSON object string such as '{"base": 0, "*": 1}'; first matching basename rule wins; unmatched images use 1; scales solved global corrections.
        joint_coregistration_local_image_movement_penalty_weights: Ordered dict[str, positive float] of wcmatch.glob basename patterns; first match wins; unmatched images and None use 1; larger weights resist local deformation.
        joint_coregistration_local_tie_alignment_strength: Number in [0, 1] for all images or JSON object string such as '{"base": 0, "*": 1}'; first matching basename rule wins; unmatched images use 1; scales solved local displacements.
        global_regression_load_adjustments: str statistics JSON path or None; a missing file warns and computes fresh statistics.
        global_regression_pif_load_ties: str selected tie-point JSON path or None; a missing file warns and detects PIF seed matches normally.
        local_block_adjustment_load_block_maps: (reference_tif_or_None, list_of_local_tifs_or_None) or None; missing files warn and their maps are computed.
        align_rasters_resolution: Shared pixel size strategy (highest, average, lowest), positive int or float pixel size in CRS units, or None to preserve native resolution.
        merge_rasters_resolution: Merge resolution strategy (highest, average, lowest) or a positive int or float specifying square output pixels in CRS units for either merge mode; default highest.
        merge_rasters_overlap: Overlap in pixels between output tiles, default 0; nonzero values require tiled merge and must be smaller than shared_window_size.
        merge_rasters_build_overviews: Build overviews using shared_window_scales, default False; tiled merge creates pyramid tiles in numbered subfolders and requires consecutive powers of two starting at 2.
        merge_rasters_resampling_method: Resampling for both merge modes: nearest (or near), bilinear, cubic, cubicspline, or lanczos, default nearest.
        merge_rasters_custom_tiles_csv: Optional .csv filename within the tile folder; GDAL writes a headerless, semicolon-delimited index with columns tilename;minx;maxx;miny;maxy in the output CRS, also in each pyramid subfolder; requires tiled merge.
        merge_rasters_create_vrts: VRT filename within the tile folder, default "MergedImage.vrt"; also creates and links pyramid VRTs as overviews; a custom name requires tiled merge.
    """
    _print_step_start("pipeline")
    Universal._validate(window_scales=shared_window_scales)
    resolved_steps = _validate_pipeline_steps(steps)
    last_step = resolved_steps[-1] if resolved_steps else None
    _validate_shared_output_for_last_step(
        shared_output_image_path=shared_output_image_path,
        last_step=last_step,
        merge_rasters_output_tiles=merge_rasters_output_tiles,
    )
    if "merge" in resolved_steps:
        UtilsValidation._validate_merge_rasters(
            output_tiles=merge_rasters_output_tiles,
            output_image_path=shared_output_image_path,
            resolution=merge_rasters_resolution,
            overlap=merge_rasters_overlap,
            window_size=shared_window_size,
            window_scales=shared_window_scales,
            build_overviews=merge_rasters_build_overviews,
            resampling_method=merge_rasters_resampling_method,
            custom_tiles_csv=merge_rasters_custom_tiles_csv,
            create_vrts=merge_rasters_create_vrts,
            resume_from_outputs=shared_resume_from_steps,
        )
    temp_dir = shared_temp_dir or tempfile.mkdtemp(prefix="spectralmatch_pipeline_")
    if delete_temp_dir and os.path.isdir(temp_dir):
        shutil.rmtree(temp_dir, ignore_errors=True)
    os.makedirs(temp_dir, exist_ok=True)

    input_image_paths = _resolve_paths(
        "search", shared_input_images, kwargs={"default_file_pattern": "*.tif"}
    )
    shared_cache, shared_image_threads, shared_io_threads, shared_tile_threads = (
        _resolve_auto_shared_settings(
            shared_input_images=shared_input_images,
            shared_cache=shared_cache,
            shared_image_threads=shared_image_threads,
            shared_io_threads=shared_io_threads,
            shared_tile_threads=shared_tile_threads,
            shared_debug_logs=shared_debug_logs,
        )
    )
    PipelineValidation._validate_shared_pipeline(
        shared_output_image_path=shared_output_image_path,
        shared_temp_dir=shared_temp_dir,
        delete_temp_dir=delete_temp_dir,
        delete_previous_step=delete_previous_step,
        shared_resume_from_steps=shared_resume_from_steps,
    )
    Universal._validate(
        input_images=shared_input_images,
        debug_logs=shared_debug_logs,
        window_size=shared_window_size,
        custom_nodata_value=shared_custom_nodata_value,
        calculation_dtype=shared_calculation_dtype,
        output_dtype=shared_output_dtype,
        cache=shared_cache,
        image_threads=shared_image_threads,
        io_threads=shared_io_threads,
        tile_threads=shared_tile_threads,
        save_as_cog=shared_save_as_cog,
        concurrent_processing_backend=shared_concurrent_processing_backend,
        dask_scheduler=shared_dask_scheduler,
    )

    start_dt = datetime.now()
    start_perf = time.perf_counter()
    print(f"Pipeline start: {start_dt.isoformat(timespec='seconds')}")
    print(f"Pipeline temp dir: {temp_dir}")
    print(f"Number of input images: {len(input_image_paths)}")

    current_images: Universal.SearchFolderOrListFiles = shared_input_images
    current_polygons: str | None = None
    current_polygon_layer: str | None = None
    seamline_mask_path: str | None = None
    seamline_mask_image_field_name: str | None = None
    previous_cleanup_paths: list[str] = []

    results: dict[str, Any] = {
        "temp_dir": temp_dir,
        "input_images": shared_input_images,
        "resolved_shared_cache": shared_cache,
        "resolved_shared_image_threads": shared_image_threads,
        "resolved_shared_io_threads": shared_io_threads,
        "resolved_shared_tile_threads": shared_tile_threads,
        "shared_concurrent_processing_backend": shared_concurrent_processing_backend,
        "shared_dask_scheduler": shared_dask_scheduler,
        "num_input_images": len(input_image_paths),
        "start_time": start_dt.isoformat(timespec="seconds"),
        "steps": resolved_steps,
        "shared_resume_from_steps": shared_resume_from_steps,
    }

    try:
        for step_index, step_name in enumerate(resolved_steps):
            is_last_step = step_index == len(resolved_steps) - 1
            step_cleanup_paths: list[str] = []

            if step_name == "joint_coregistration":
                output_images = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                current_images = joint_coregistration(
                    input_images=current_images,
                    output_images=output_images,
                    tie_feature_method=joint_coregistration_tie_feature_method,
                    tie_grid_spacing=joint_coregistration_tie_grid_spacing,
                    tie_search_radius=joint_coregistration_tie_search_radius,
                    tie_orb_max_features=joint_coregistration_tie_orb_max_features,
                    tie_max_matches_per_window=joint_coregistration_tie_max_matches_per_window,
                    tie_maximum_displacement=joint_coregistration_tie_maximum_displacement,
                    tie_ransac_reprojection_threshold=joint_coregistration_tie_ransac_reprojection_threshold,
                    tie_robust_loss=joint_coregistration_tie_robust_loss,
                    tie_robust_loss_scale=joint_coregistration_tie_robust_loss_scale,
                    tie_save_path=joint_coregistration_tie_save_path,
                    tie_save_crs_path=joint_coregistration_tie_save_crs_path,
                    tie_load_path=joint_coregistration_tie_load_path,
                    global_model=joint_coregistration_global_model,
                    global_image_movement_penalty_weights=joint_coregistration_global_image_movement_penalty_weights,
                    global_tie_alignment_strength=joint_coregistration_global_tie_alignment_strength,
                    local_model=joint_coregistration_local_model,
                    local_image_movement_penalty_weights=joint_coregistration_local_image_movement_penalty_weights,
                    local_tie_alignment_strength=joint_coregistration_local_tie_alignment_strength,
                    local_grid_spacing=joint_coregistration_local_grid_spacing,
                    local_smoothness_weight=joint_coregistration_local_smoothness_weight,
                    local_bending_weight=joint_coregistration_local_bending_weight,
                    local_anchor_falloff_distance=joint_coregistration_local_anchor_falloff_distance,
                    resampling_method=joint_coregistration_resampling_method,
                    tap=joint_coregistration_tap,
                    resolution=joint_coregistration_resolution,
                    output_dtype=shared_output_dtype,
                    custom_nodata_value=shared_custom_nodata_value,
                    window_size=shared_window_size,
                    save_as_cog=shared_save_as_cog,
                    build_overviews=joint_coregistration_build_overviews,
                    window_scales=shared_window_scales,
                    cache=shared_cache,
                    image_threads=shared_image_threads,
                    io_threads=shared_io_threads,
                    tile_threads=shared_tile_threads,
                    concurrent_processing_backend=shared_concurrent_processing_backend,
                    dask_scheduler=shared_dask_scheduler,
                    debug_logs=shared_debug_logs,
                    resume_from_outputs=shared_resume_from_steps,
                )
                results["joint_coregistration"] = current_images
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, current_images, temp_dir
                )

            elif step_name == "global_regression":
                output_images = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                current_images = Match.global_regression(
                    input_images=current_images,
                    output_images=output_images,
                    calculation_dtype=shared_calculation_dtype,
                    output_dtype=shared_output_dtype,
                    vector_mask=global_regression_vector_mask,
                    debug_logs=shared_debug_logs,
                    custom_nodata_value=shared_custom_nodata_value,
                    cache=shared_cache,
                    image_threads=shared_image_threads,
                    io_threads=shared_io_threads,
                    tile_threads=shared_tile_threads,
                    concurrent_processing_backend=shared_concurrent_processing_backend,
                    dask_scheduler=shared_dask_scheduler,
                    window_size=shared_window_size,
                    save_as_cog=shared_save_as_cog,
                    estimate_stats=global_regression_estimate_stats,
                    specify_model_images=global_regression_specify_model_images,
                    custom_mean_factor=global_regression_custom_mean_factor,
                    custom_std_factor=global_regression_custom_std_factor,
                    save_adjustments=global_regression_save_adjustments,
                    load_adjustments=global_regression_load_adjustments,
                    pif_method=global_regression_pif_method,
                    pif_red_band_index=global_regression_pif_red_band_index,
                    pif_nir_band_index=global_regression_pif_nir_band_index,
                    pif_vegetation_threshold=global_regression_pif_vegetation_threshold,
                    pif_inz_threshold=global_regression_pif_inz_threshold,
                    pif_region_radius=global_regression_pif_region_radius,
                    pif_max_samples=global_regression_pif_max_samples,
                    pif_min_samples=global_regression_pif_min_samples,
                    pif_feature_method=global_regression_pif_feature_method,
                    pif_load_ties=global_regression_pif_load_ties,
                    pif_save_inz=global_regression_pif_save_inz,
                    build_overviews=global_regression_build_overviews,
                    window_scales=shared_window_scales,
                    resume_from_outputs=shared_resume_from_steps,
                )
                results["global_regression"] = current_images
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, current_images, temp_dir
                )

            elif step_name == "local_block_adjustment":
                output_images = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                current_images = Match.local_block_adjustment(
                    input_images=current_images,
                    output_images=output_images,
                    calculation_dtype=shared_calculation_dtype,
                    output_dtype=shared_output_dtype,
                    vector_mask=local_block_adjustment_vector_mask,
                    debug_logs=shared_debug_logs,
                    custom_nodata_value=shared_custom_nodata_value,
                    cache=shared_cache,
                    image_threads=shared_image_threads,
                    io_threads=shared_io_threads,
                    tile_threads=shared_tile_threads,
                    concurrent_processing_backend=shared_concurrent_processing_backend,
                    dask_scheduler=shared_dask_scheduler,
                    window_size=shared_window_size,
                    save_as_cog=shared_save_as_cog,
                    number_of_blocks=local_block_adjustment_number_of_blocks,
                    alpha=local_block_adjustment_alpha,
                    correction_method=local_block_adjustment_correction_method,
                    save_block_maps=local_block_adjustment_save_block_maps,
                    load_block_maps=local_block_adjustment_load_block_maps,
                    override_bounds_canvas_coords=local_block_adjustment_override_bounds_canvas_coords,
                    build_overviews=local_block_adjustment_build_overviews,
                    window_scales=shared_window_scales,
                    resume_from_outputs=shared_resume_from_steps,
                )
                results["local_block_adjustment"] = current_images
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, current_images, temp_dir
                )

            elif step_name == "align":
                output_images = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                current_images = align_rasters(
                    input_images=current_images,
                    output_images=output_images,
                    resampling_method=align_rasters_resampling_method,
                    tap=align_rasters_tap,
                    resolution=align_rasters_resolution,
                    window_size=shared_window_size,
                    debug_logs=shared_debug_logs,
                    cache=shared_cache,
                    image_threads=shared_image_threads,
                    io_threads=shared_io_threads,
                    tile_threads=shared_tile_threads,
                    concurrent_processing_backend=shared_concurrent_processing_backend,
                    dask_scheduler=shared_dask_scheduler,
                    resume_from_outputs=shared_resume_from_steps,
                )
                results["align"] = current_images
                results["align_rasters"] = current_images
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, current_images, temp_dir
                )

            elif step_name == "create_footprints":
                output_polygons = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                current_polygons = Seamline.create_footprints(
                    input_images=current_images,
                    output_polygons=output_polygons,
                    image_field_name=create_footprints_image_field_name,
                    output_layer=create_footprints_output_layer,
                    band=create_footprints_band,
                    eight_connected=create_footprints_eight_connected,
                    image_threads=shared_image_threads,
                    concurrent_processing_backend=shared_concurrent_processing_backend,
                    dask_scheduler=shared_dask_scheduler,
                    debug_logs=shared_debug_logs,
                    resume_from_outputs=shared_resume_from_steps,
                )
                current_polygon_layer = create_footprints_output_layer
                results[step_name] = current_polygons
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, current_polygons, temp_dir
                )

            elif step_name == "postprocess_footprints":
                input_polygons = postprocess_footprints_input_polygons
                input_layer = postprocess_footprints_input_layer
                if input_polygons is None:
                    input_polygons = current_polygons
                    if input_layer is None:
                        input_layer = current_polygon_layer
                if input_polygons is None:
                    raise ValueError(
                        "postprocess_footprints requires input polygons. Set "
                        "postprocess_footprints_input_polygons or run create_footprints earlier in the pipeline."
                    )
                output_polygons = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                current_polygons = Seamline.postprocess_footprints(
                    input_polygons=input_polygons,
                    output_polygons=output_polygons,
                    input_layer=input_layer,
                    output_layer=postprocess_footprints_output_layer,
                    edge_distance=postprocess_footprints_edge_distance,
                    hole_to_hole_distance=postprocess_footprints_hole_to_hole_distance,
                    relative_edge_distance=postprocess_footprints_relative_edge_distance,
                    cut_width=postprocess_footprints_cut_width,
                    cut_method=postprocess_footprints_cut_method,
                    smoothing_radius=postprocess_footprints_smoothing_radius,
                    simplify_tolerance=postprocess_footprints_simplify_tolerance,
                    simplify_area_weight=postprocess_footprints_simplify_area_weight,
                    area_filter=postprocess_footprints_area_filter,
                    area_rank=postprocess_footprints_area_rank,
                    image_threads=shared_image_threads,
                    concurrent_processing_backend=shared_concurrent_processing_backend,
                    dask_scheduler=shared_dask_scheduler,
                    debug_logs=shared_debug_logs,
                    resume_from_outputs=shared_resume_from_steps,
                )
                current_polygon_layer = postprocess_footprints_output_layer
                results[step_name] = current_polygons
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, current_polygons, temp_dir
                )

            elif step_name == "voronoi_center_seamline":
                seamline_mask_path = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                if not isinstance(seamline_mask_path, str):
                    raise ValueError(
                        "shared_output_image_path must be a single file path when the final step is a seamline."
                    )
                seamline_mask_image_field_name = voronoi_center_seamline_image_field_name
                input_polygons = voronoi_center_seamline_input_polygons
                input_layer = voronoi_center_seamline_input_layer
                if input_polygons is None:
                    input_polygons = current_polygons
                    if input_layer is None:
                        input_layer = current_polygon_layer
                if input_polygons is None:
                    input_layer = input_layer or create_footprints_output_layer
                    input_polygons = Seamline.create_footprints(
                        input_images=current_images,
                        output_polygons=_step_temp_output("create_footprints", temp_dir),
                        image_field_name=(
                            voronoi_center_seamline_image_field_name
                            if create_footprints_image_field_name == "image"
                            else create_footprints_image_field_name
                        ),
                        output_layer=input_layer,
                        band=create_footprints_band,
                        eight_connected=create_footprints_eight_connected,
                        image_threads=shared_image_threads,
                        concurrent_processing_backend=shared_concurrent_processing_backend,
                        dask_scheduler=shared_dask_scheduler,
                        debug_logs=shared_debug_logs,
                        resume_from_outputs=shared_resume_from_steps,
                    )
                    current_polygons = input_polygons
                    current_polygon_layer = input_layer
                    results["create_footprints"] = input_polygons
                    previous_cleanup_paths.extend(
                        _collect_step_cleanup_paths("create_footprints", input_polygons, temp_dir)
                    )
                Seamline.voronoi(
                    input_polygons=input_polygons,
                    output_mask=seamline_mask_path,
                    aoi_path=voronoi_center_seamline_aoi_path,
                    input_layer=input_layer,
                    output_layer=voronoi_center_seamline_output_layer,
                    image_field_name=voronoi_center_seamline_image_field_name,
                    min_point_spacing=voronoi_center_seamline_min_point_spacing,
                    min_cut_length=voronoi_center_seamline_min_cut_length,
                    debug_logs=shared_debug_logs,
                    debug_vectors_path=voronoi_center_seamline_debug_vectors_path,
                    resume_from_outputs=shared_resume_from_steps,
                )
                results["voronoi_center_seamline"] = seamline_mask_path
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, seamline_mask_path, temp_dir
                )

            elif step_name == "weighted_seamline":
                seamline_mask_path = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                if not isinstance(seamline_mask_path, str):
                    raise ValueError(
                        "shared_output_image_path must be a single file path when the final step is a seamline."
                    )
                seamline_mask_image_field_name = weighted_seamline_image_field_name
                input_polygons = weighted_seamline_input_polygons
                input_layer = weighted_seamline_input_layer
                if input_polygons is None:
                    input_polygons = current_polygons
                    if input_layer is None:
                        input_layer = current_polygon_layer
                if input_polygons is None:
                    raise ValueError(
                        "weighted_seamline requires input polygons. Set "
                        "weighted_seamline_input_polygons or run a footprint step earlier in the pipeline."
                    )
                Seamline.weighted(
                    input_polygons=input_polygons,
                    output_mask=seamline_mask_path,
                    rank_function=weighted_seamline_rank_function,
                    image_field_name=weighted_seamline_image_field_name,
                    input_layer=input_layer,
                    output_layer=weighted_seamline_output_layer,
                    rank_descending=weighted_seamline_rank_descending,
                    debug_logs=shared_debug_logs,
                    resume_from_outputs=shared_resume_from_steps,
                )
                results["weighted_seamline"] = seamline_mask_path
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, seamline_mask_path, temp_dir
                )

            elif step_name == "mask":
                output_images = (
                    shared_output_image_path
                    if is_last_step
                    else _step_temp_output(step_name, temp_dir)
                )
                clip_vector_mask = mask_rasters_vector_mask
                if clip_vector_mask is None and seamline_mask_path is not None:
                    clip_vector_mask = (
                        "include",
                        seamline_mask_path,
                        seamline_mask_image_field_name,
                    )
                if clip_vector_mask is None:
                    raise ValueError(
                        "mask_rasters requires a vector mask. Set mask_rasters_vector_mask "
                        "or run a seamline step earlier in the pipeline."
                    )

                current_images = mask_rasters(
                    input_images=current_images,
                    output_images=output_images,
                    vector_mask=clip_vector_mask,
                    window_size=shared_window_size,
                    debug_logs=shared_debug_logs,
                    cache=shared_cache,
                    image_threads=shared_image_threads,
                    io_threads=shared_io_threads,
                    tile_threads=shared_tile_threads,
                    concurrent_processing_backend=shared_concurrent_processing_backend,
                    dask_scheduler=shared_dask_scheduler,
                    include_touched_pixels=mask_rasters_include_touched_pixels,
                    custom_nodata_value=shared_custom_nodata_value,
                    resume_from_outputs=shared_resume_from_steps,
                )
                results["mask"] = current_images
                results["mask_rasters"] = current_images
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, current_images, temp_dir
                )

            elif step_name == "merge":
                if not isinstance(shared_output_image_path, str):
                    raise ValueError(
                        "shared_output_image_path must be a path string for merge (a folder when merge_rasters_output_tiles=True)."
                    )
                merged_output = merge_rasters(
                    input_images=current_images,
                    output_image_path=shared_output_image_path,
                    output_tiles=merge_rasters_output_tiles,
                    cache=shared_cache,
                    image_threads=shared_image_threads if merge_rasters_output_tiles else None,
                    concurrent_processing_backend=shared_concurrent_processing_backend if merge_rasters_output_tiles else None,
                    dask_scheduler=shared_dask_scheduler if merge_rasters_output_tiles else None,
                    io_threads=shared_io_threads,
                    tile_threads=shared_tile_threads,
                    debug_logs=shared_debug_logs,
                    output_dtype=shared_output_dtype,
                    custom_nodata_value=shared_custom_nodata_value,
                    resolution=merge_rasters_resolution,
                    overlap=merge_rasters_overlap,
                    resampling_method=merge_rasters_resampling_method,
                    custom_tiles_csv=merge_rasters_custom_tiles_csv,
                    create_vrts=merge_rasters_create_vrts,
                    window_size=shared_window_size,
                    build_overviews=merge_rasters_build_overviews,
                    window_scales=shared_window_scales,
                    resume_from_outputs=shared_resume_from_steps,
                )
                current_images = merged_output
                results["merge"] = merged_output
                results["merge_rasters"] = merged_output
                step_cleanup_paths = _collect_step_cleanup_paths(
                    step_name, merged_output, temp_dir
                )

            else:
                raise ValueError(f"Unsupported pipeline step: {step_name}")

            previous_cleanup_paths.extend(step_cleanup_paths)
            if delete_previous_step and previous_cleanup_paths:
                # Rasters remain active through vector steps. Keep polygons until
                # their last consumer, including consumers after intervening steps.
                polygons_are_active = (
                    (is_last_step and step_name in FOOTPRINT_STEPS)
                    or any(
                        upcoming in SEAMLINE_STEPS | {"postprocess_footprints"}
                        for upcoming in resolved_steps[step_index + 1 :]
                    )
                )
                previous_cleanup_paths = _delete_step_outputs_if_inactive(
                    previous_cleanup_paths=previous_cleanup_paths,
                    current_images=current_images,
                    seamline_mask_path=seamline_mask_path,
                    current_polygons=current_polygons if polygons_are_active else None,
                    temp_dir=temp_dir,
                    debug_logs=shared_debug_logs,
                )

        if not resolved_steps:
            results["output"] = current_images
        elif last_step in SEAMLINE_STEPS:
            results["output"] = seamline_mask_path
        elif last_step in FOOTPRINT_STEPS:
            results["output"] = current_polygons
        else:
            results["output"] = current_images

        end_dt = datetime.now()
        duration_seconds = round(time.perf_counter() - start_perf, 2)

        final_results = {
            "output": results["output"],
            "temp_dir": temp_dir,
            "num_input_images": len(input_image_paths),
            "start_time": start_dt.isoformat(timespec="seconds"),
            "end_time": end_dt.isoformat(timespec="seconds"),
            "duration_seconds": duration_seconds,
            "resolved_shared_cache": shared_cache,
            "resolved_shared_image_threads": shared_image_threads,
            "resolved_shared_io_threads": shared_io_threads,
            "resolved_shared_tile_threads": shared_tile_threads,
        }
        for key, value in results.items():
            if key not in final_results and value is not None:
                final_results[key] = value
        return final_results
    finally:
        if delete_temp_dir and os.path.isdir(temp_dir):
            shutil.rmtree(temp_dir, ignore_errors=True)