Skip to content

Commit

Permalink
Scale images in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Apr 1, 2019
1 parent 252d2a9 commit 49dab85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions process
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,16 @@ def output(cmd: List[str], **kwargs) -> str:


def image_diff(image1, image2):
if image1.shape != image2.shape:
print("The tow images don't have the same size {}x{} != {}x{}.".format(
image1.shape[0], image1.shape[1], image2.shape[0], image2.shape[1]
))
return 9999, None
width = max(image1.shape[0], image2.shape[0])
height = max(image1.shape[1], image2.shape[1])
image1 = cv2.resize(image1, (width, height), interpolation=cv2.INTER_CUBIC)
image2 = cv2.resize(image2, (width, height), interpolation=cv2.INTER_CUBIC)
score, diff = compare_ssim(
cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY),
cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY),
full=True
)
diff = (diff * 255).astype("uint8")
diff = (255 - diff * 255).astype("uint8")
return score, diff


Expand Down Expand Up @@ -118,8 +117,8 @@ class Process: # pylint: disable=too-few-public-methods
raise Exception("No generated image...")
context.image = new_image
if self.experimental and context.image is not None:
_, diff = image_diff(old_image, context.image)
if diff is not None:
score, diff = image_diff(old_image, context.image)
if diff is not None and score < 1.0:
dest_folder = os.path.join(context.root_folder, self.name)
if not os.path.exists(dest_folder):
os.makedirs(dest_folder)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def check_image(root_folder, image, name):
score, diff = process.image_diff(expected, result)
if diff is not None:
cv2.imwrite(os.path.join(root_folder, '{}.diff.png'.format(name)), diff)
assert score < 2, '{} ({}) != {} ({})'.format(expected, result, expected_name, image)
assert score > 0.99, '{} ({}) != {} ({})'.format(expected, result, expected_name, image)


@pytest.mark.parametrize('type_,limit', [
Expand Down

0 comments on commit 49dab85

Please sign in to comment.