diff --git a/CHANGELOG.md b/CHANGELOG.md index ccfc4bb6..16c0f874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.7.6 + +* fix a bug where invalid zoom factor lead to exceptions; now invalid zoom factors results in no scaling of the image + ## 0.7.5 * Improved packaging diff --git a/test_unstructured_inference/models/test_tables.py b/test_unstructured_inference/models/test_tables.py index c6d3371a..a96ef942 100644 --- a/test_unstructured_inference/models/test_tables.py +++ b/test_unstructured_inference/models/test_tables.py @@ -605,6 +605,17 @@ def test_auto_zoom(mocker): assert spy.call_count == 1 +@pytest.mark.parametrize("zoom", [1, 0.1, 5, -1, 0]) +def test_zoom_image(example_image, zoom): + width, height = example_image.size + new_image = tables.zoom_image(example_image, zoom) + new_w, new_h = new_image.size + if zoom <= 0: + zoom = 1 + assert new_w == np.round(width * zoom, 0) + assert new_h == np.round(height * zoom, 0) + + def test_padded_results_has_right_dimensions(table_transformer, example_image): str_class_name2idx = tables.get_class_map("structure") # a simpler mapping so we keep all structure in the returned objs below for test diff --git a/unstructured_inference/__version__.py b/unstructured_inference/__version__.py index 66a9fc3b..11322ac5 100644 --- a/unstructured_inference/__version__.py +++ b/unstructured_inference/__version__.py @@ -1 +1 @@ -__version__ = "0.7.5" # pragma: no cover +__version__ = "0.7.6" # pragma: no cover diff --git a/unstructured_inference/models/tables.py b/unstructured_inference/models/tables.py index 6b29fe78..d474e330 100644 --- a/unstructured_inference/models/tables.py +++ b/unstructured_inference/models/tables.py @@ -719,6 +719,9 @@ def cells_to_html(cells): def zoom_image(image: Image, zoom: float) -> Image: """scale an image based on the zoom factor using cv2; the scaled image is post processed by dilation then erosion to improve edge sharpness for OCR tasks""" + if zoom <= 0: + # no zoom but still does dilation and erosion + zoom = 1 new_image = cv2.resize( cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR), None,