Pull request #30: RED-5202 add per class customizable max_rel_image_size configuration.
Merge in RR/image-prediction from RED-5202-add-class-specific-image-size-heuristic to release/1.2.x * commit 'f48455c496a12d99bb8e9e015d61f661bd94519b': RED-5202 add per class customizable max_rel_image_size configuration. If value isn't set or isn't defined at all for a class, the default value is used (change is backwards compatible). Custom value enabled for signatures, set to 0.4 relative image size if not overwritten by ENV (; set to null to use default value or define custom value. Value is 0.4 if ENV is not found.)
This commit is contained in:
commit
2a62c4fca2
@ -18,6 +18,10 @@ filters:
|
|||||||
image_to_page_quotient: # Image size to page size ratio (ratio of geometric means of areas)
|
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
|
min: $MIN_REL_IMAGE_SIZE|0.05 # Minimum permissible
|
||||||
max: $MAX_REL_IMAGE_SIZE|0.75 # Maximum 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
|
image_width_to_height_quotient: # Image width to height ratio
|
||||||
min: $MIN_IMAGE_FORMAT|0.1 # Minimum permissible
|
min: $MIN_IMAGE_FORMAT|0.1 # Minimum permissible
|
||||||
|
|||||||
@ -15,6 +15,12 @@ class DotIndexable:
|
|||||||
def __init__(self, x):
|
def __init__(self, x):
|
||||||
self.x = 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):
|
def __getattr__(self, item):
|
||||||
return _get_item_and_maybe_make_dotindexable(self.x, item)
|
return _get_item_and_maybe_make_dotindexable(self.x, item)
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,13 @@ def build_image_info(data: dict) -> dict:
|
|||||||
image_area_sqrt = math.sqrt(abs(x2 - x1) * abs(y2 - y1))
|
image_area_sqrt = math.sqrt(abs(x2 - x1) * abs(y2 - y1))
|
||||||
return image_area_sqrt / page_area_sqrt
|
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 = itemgetter(
|
||||||
"page_width", "page_height", "x1", "x2", "y1", "y2", "width", "height", "alpha"
|
"page_width", "page_height", "x1", "x2", "y1", "y2", "width", "height", "alpha"
|
||||||
)(data)
|
)(data)
|
||||||
@ -27,7 +34,9 @@ def build_image_info(data: dict) -> dict:
|
|||||||
quotient = round(compute_geometric_quotient(), 4)
|
quotient = round(compute_geometric_quotient(), 4)
|
||||||
|
|
||||||
min_image_to_page_quotient_breached = bool(quotient < CONFIG.filters.image_to_page_quotient.min)
|
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(
|
min_image_width_to_height_quotient_breached = bool(
|
||||||
width / height < CONFIG.filters.image_width_to_height_quotient.min
|
width / height < CONFIG.filters.image_width_to_height_quotient.min
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user