Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make image similarity check less sensitive #258

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
python-version: '3.9'
- run: sudo apt-get update
- run: sudo apt-get install --fix-missing ffmpeg python3-soundfile
- run: pip install pyre-check pytest
- run: pip install pyre-check pytest imagehash
- run: pip install -e .[all]
- run: pyre --source-directory "." --noninteractive check || true
- run: pytest --durations=10 .
8 changes: 5 additions & 3 deletions augly/image/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,9 @@ def overlay_wrap_text(
color = (rand.randrange(255), rand.randrange(255), rand.randrange(255))

red, green, blue = color
draw = ImageDraw.Draw(image)
aug_image = image.copy()

draw = ImageDraw.Draw(aug_image)
for line in lines:
# draw text on the image
draw.text(
Expand All @@ -1726,11 +1728,11 @@ def overlay_wrap_text(
imutils.get_metadata(
metadata=metadata,
function_name="overlay_wrap_text",
aug_image=image,
aug_image=aug_image,
**func_kwargs,
)

return imutils.ret_and_save_image(image, output_path, src_mode)
return imutils.ret_and_save_image(aug_image, output_path, src_mode)


def pad(
Expand Down
7 changes: 5 additions & 2 deletions augly/tests/image_tests/base_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
import unittest
from typing import Any, Callable, Dict, List, Optional

import numpy as np
import imagehash
from augly.tests import ImageAugConfig
from augly.utils import pathmgr, TEST_URI
from PIL import Image


def are_equal_images(a: Image.Image, b: Image.Image) -> bool:
return a.size == b.size and np.allclose(np.array(a), np.array(b))
threshold = 0 # hamming distance of 0 is forgiving enough for phash
a_hash = imagehash.phash(a)
b_hash = imagehash.phash(b)
return a.size == b.size and a_hash - b_hash == threshold


def are_equal_metadata(
Expand Down
Loading