from typing import Iterable from image_prediction.image_extractor.extractor import ImageMetadataPair from image_prediction.stitching.merging import merge_along_both_axes, no_new_merges from image_prediction.utils.generic import until def stitch_pairs(pairs: Iterable[ImageMetadataPair]) -> Iterable[ImageMetadataPair]: """Given a collection of image-metadata pairs from the same pages, combines all pairs that constitute adjacent images.""" return until(no_new_merges, merge_along_both_axes, pairs)