Skip to content

Commit

Permalink
Merge pull request #26 from andreped/fix-color-test
Browse files Browse the repository at this point in the history
Fixed RGB/LAB unit test
  • Loading branch information
carloalbertobarbano committed Jan 17, 2023
2 parents 8b02b9f + 8d2beb7 commit c73860c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/test_color_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import cv2
import os

def test_rgb_to_lab():
def test_rgb_lab():
size = 1024
curr_file_path = os.path.dirname(os.path.realpath(__file__))
img = cv2.resize(cv2.cvtColor(cv2.imread(os.path.join(curr_file_path, "../data/source.png")), cv2.COLOR_BGR2RGB), (size, size))

# rgb2lab expects data to be float32 in range [0, 1]
img = img / 255

# convert from RGB to LAB and back again to RGB
reconstructed_img = lab2rgb(rgb2lab(img))
val = np.mean(np.abs(reconstructed_img - img))
print("MAE:", val)
assert val < 0.1

# assess if the reconstructed image is similar to the original image
np.testing.assert_almost_equal(np.mean(np.abs(reconstructed_img - img)), 0.0, decimal=4, verbose=True)

0 comments on commit c73860c

Please sign in to comment.