diff --git a/config.yaml b/config.yaml index 6a6111a..053f4dd 100644 --- a/config.yaml +++ b/config.yaml @@ -18,6 +18,10 @@ filters: image_to_page_quotient: # Image size to page size ratio (ratio of geometric means of areas) min: $MIN_REL_IMAGE_SIZE|0.05 # Minimum permissible max: $MAX_REL_IMAGE_SIZE|0.75 # Maximum permissible + customized: # Customized settings per class (RED-5202) + max: + signature: $MAX_REL_SIGNATURE_SIZE|0.4 + image_width_to_height_quotient: # Image width to height ratio min: $MIN_IMAGE_FORMAT|0.1 # Minimum permissible diff --git a/image_prediction/config.py b/image_prediction/config.py index 4696191..98d2af1 100644 --- a/image_prediction/config.py +++ b/image_prediction/config.py @@ -15,6 +15,12 @@ class DotIndexable: def __init__(self, x): self.x = x + def get(self, item, default=None): + try: + return _get_item_and_maybe_make_dotindexable(self.x, item) + except KeyError: + return default + def __getattr__(self, item): return _get_item_and_maybe_make_dotindexable(self.x, item) diff --git a/image_prediction/transformer/transformers/response.py b/image_prediction/transformer/transformers/response.py index 3e35104..0fdc862 100644 --- a/image_prediction/transformer/transformers/response.py +++ b/image_prediction/transformer/transformers/response.py @@ -20,6 +20,13 @@ def build_image_info(data: dict) -> dict: image_area_sqrt = math.sqrt(abs(x2 - x1) * abs(y2 - y1)) return image_area_sqrt / page_area_sqrt + def is_max_image_to_page_quotient_breached(quotient, label): + default_max_quotient = CONFIG.filters.image_to_page_quotient.max + customized_entries = CONFIG.filters.image_to_page_quotient.customized.max + max_quotient = customized_entries.get(label, default_max_quotient) + max_quotient = max_quotient if max_quotient else default_max_quotient + return bool(quotient > max_quotient) + page_width, page_height, x1, x2, y1, y2, width, height, alpha = itemgetter( "page_width", "page_height", "x1", "x2", "y1", "y2", "width", "height", "alpha" )(data) @@ -27,7 +34,9 @@ def build_image_info(data: dict) -> dict: quotient = round(compute_geometric_quotient(), 4) min_image_to_page_quotient_breached = bool(quotient < CONFIG.filters.image_to_page_quotient.min) - max_image_to_page_quotient_breached = bool(quotient > CONFIG.filters.image_to_page_quotient.max) + max_image_to_page_quotient_breached = is_max_image_to_page_quotient_breached( + quotient, data["classification"]["label"] + ) min_image_width_to_height_quotient_breached = bool( width / height < CONFIG.filters.image_width_to_height_quotient.min )