Skip to content

Commit

Permalink
compare avg hash instead of full image array
Browse files Browse the repository at this point in the history
  • Loading branch information
gizemozd committed Jul 1, 2024
1 parent e473634 commit 2bc118e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/test_plot_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import numpy as np
import matplotlib.pyplot as plt

from PIL import Image
import imagehash

import seqikpy
from seqikpy.visualization import (
load_grid_plot_data,
Expand Down Expand Up @@ -137,11 +140,8 @@ def test_grid_plot():
export_path=PKG_PATH / "../tests" / f'generate_frame_{t}.png',
**plot_config
)
# Load the ground truth and generated images
img_ground_truth = plt.imread(PKG_PATH / "../tests" / 'test_frame_100.png')
img_test = plt.imread(PKG_PATH / "../tests" / f'generate_frame_{t}.png')
# Convert colors to compare in a more robust way
img_ground_truth = np.where(img_ground_truth > 0, 1, 0)
img_test = np.where(img_test > 0, 1, 0)

assert np.allclose(img_ground_truth, img_test)

true_hash = imagehash.average_hash(Image.open(PKG_PATH / "../tests" / 'test_frame_100.png'))
generated_hash = imagehash.average_hash(Image.open(PKG_PATH / "../tests" / f'generate_frame_{t}.png'))

assert (true_hash - generated_hash) <= 5, "The generated image is not similar to the true image"

0 comments on commit 2bc118e

Please sign in to comment.