diff --git a/image_prediction/stitching/merging.py b/image_prediction/stitching/merging.py index 7f4442c..96da32b 100644 --- a/image_prediction/stitching/merging.py +++ b/image_prediction/stitching/merging.py @@ -3,15 +3,18 @@ from functools import reduce from typing import Iterable, Callable, List from PIL import Image -from funcy import juxt, first, rest, rcompose, rpartial, complement, ilen +from funcy import juxt, first, rest, rcompose, rpartial from image_prediction.image_extractor.extractor import ImageMetadataPair from image_prediction.info import Info from image_prediction.stitching.grouping import CoordGrouper from image_prediction.stitching.split_mapper import HorizontalSplitMapper, VerticalSplitMapper from image_prediction.stitching.utils import make_coord_getter, flatten_groups_once, validate_box +from image_prediction.utils import get_logger from image_prediction.utils.generic import until +logger = get_logger() + def make_merger_sentinel(): def no_new_mergers(pairs): @@ -184,7 +187,10 @@ def concat_images(im1: Image, im2: Image, metadata: dict, axis): for im, offset in zip(images, offsets): box = (offset, 0) if not axis else (0, offset) - # TODO: replace image that cannot be opened with white image of same size - im_aggr.paste(im, box=box) + + try: # RED-5170: fails if image is 'broken' + im_aggr.paste(im, box=box) + except Exception as err: + logger.warn(f"{err}: couldn't merge images, replace and passthrough. (page: {metadata[Info.PAGE_IDX]})") return im_aggr