Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions test_unstructured_inference/models/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion unstructured_inference/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.5" # pragma: no cover
__version__ = "0.7.6" # pragma: no cover
3 changes: 3 additions & 0 deletions unstructured_inference/models/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down