Skip to content

Commit

Permalink
fix: adapt to newer version of scikit-image
Browse files Browse the repository at this point in the history
  • Loading branch information
Latios96 committed Oct 8, 2024
1 parent 79ce452 commit 5f9dcf2
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 10 deletions.
10 changes: 8 additions & 2 deletions cato_common/images/image_comparators/ssim_image_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def compare(
reference_image = self._normalize_image(reference_image)

(score, diff) = metrics.structural_similarity(
reference_image, output_image, full=True, channel_axis=-1
reference_image,
output_image,
full=True,
channel_axis=-1,
data_range=output_image.max() - output_image.min(),
)
score = float(score)
if math.isnan(score):
Expand Down Expand Up @@ -145,7 +149,9 @@ def _create_diff_image(

composited_diff_image = Image.composite(output_image, heatmap, l_thresholded)
target_path = os.path.join(workdir, f"diff_image_{uuid.uuid4()}.png")
composited_diff_image.save(target_path)
no_alpha = Image.new("RGB", composited_diff_image.size, (0, 0, 0))
no_alpha.paste(composited_diff_image, (0, 0), composited_diff_image)
no_alpha.save(target_path)
return target_path

def _normalize_image(self, image):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
[INFO] Found image output at path <foo>
[INFO] Found image output at path <bar>
[INFO] Comparing images locally..
[INFO] PythonOutputVersion succeeded in 0.12 seconds
[INFO] Reporting test result of test PythonTestSuite/PythonOutputVersion..
[INFO] Uploading output of test PythonTestSuite/PythonOutputVersion..
Expand Down
4 changes: 4 additions & 0 deletions tests/integrationtests/cato_cmd/test_cato_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def test_worker_run_command(
"Copy .* to .*": "Copy <a> to <b>",
"Found image output at path .*": "Found image output at path <foo>",
"Found reference image at path .*": "Found image output at path <bar>",
".*RuntimeWarning.*": "",
".*S = \(A1.*": "",
".*heatmap.clip.*": "",
".*cv2.cvtColor.*": "",
},
env=env_with_api_token,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integrationtests/cato_cmd/test_run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ def assert_the_success_result_is_available_on_the_server(
"id": 2,
"name": "write_black_image",
"testIdentifier": "WriteImages/write_black_image",
"thumbnailFileId": 16,
"thumbnailFileId": 14,
},
{
"unifiedTestStatus": "SUCCESS",
"id": 1,
"name": "write_white_image",
"testIdentifier": "WriteImages/write_white_image",
"thumbnailFileId": 8,
"thumbnailFileId": 7,
},
]

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/resources/sphere_test_images/expected_diff_ssim/jpeg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/resources/with_watermark_diff_ssim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def test_compare_image_should_fail_one_pixel_different(

assert comparison_result == ComparisonResult(
status=ResultStatus.FAILED,
message="Images are not equal! SSIM score was 0.995, max threshold is 1.000",
message="Images are not equal! SSIM score was 0.994, max threshold is 1.000",
diff_image=str(
tmpdir.join("diff_image_c04b964d-f443-4ae9-8b43-47fe6d2422d0.png")
),
error=0.994861900806427,
error=0.9944998621940613,
)


Expand All @@ -84,9 +84,9 @@ def test_compare_image_should_fail_waith_and_without_watermark(

assert comparison_result == ComparisonResult(
status=ResultStatus.FAILED,
message="Images are not equal! SSIM score was 0.918, max threshold is 1.000",
message="Images are not equal! SSIM score was 0.911, max threshold is 1.000",
diff_image=tmpdir.join("diff_image_c04b964d-f443-4ae9-8b43-47fe6d2422d0.png"),
error=0.9175751805305481,
error=0.9112997651100159,
)
assert images_are_equal(
comparison_result.diff_image,
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_compare_image_should_succeed_threshold_not_exceeded(
status=ResultStatus.SUCCESS,
message=None,
diff_image=tmpdir.join("diff_image_c04b964d-f443-4ae9-8b43-47fe6d2422d0.png"),
error=0.9175751805305481,
error=0.9112997651100159,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def images_are_visually_equal(image1, image2, threshold):
)

(score, diff) = metrics.structural_similarity(
image_one, image_two, full=True, multichannel=True
image_one,
image_two,
full=True,
channel_axis=-1,
data_range=image_two.max() - image_two.min(),
)
print(score)
return score > threshold

0 comments on commit 5f9dcf2

Please sign in to comment.