From 7c6f9809bc6ff386a0fc49fa0886b9b970f6ae6f Mon Sep 17 00:00:00 2001 From: Julius Unverfehrt Date: Tue, 30 Aug 2022 08:35:48 +0200 Subject: [PATCH] add support to image stitching for broken images (replace broken part by empty image) --- image_prediction/stitching/merging.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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