Skip to content

Commit

Permalink
working tests for LAB color conversions using ImagingCMS
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Oct 16, 2013
1 parent bde4613 commit deb424c
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions Tests/test_imagecms.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ def test_display_profile():
def test_lab_color_profile():
pLab = ImageCms.createProfile("LAB", 5000)
pLab = ImageCms.createProfile("LAB", 6500)

def test_simple_lab():
i = Image.new('RGB', (10,10), (128,128,128))

pLab = ImageCms.createProfile("LAB")
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")

i_lab = ImageCms.applyTransform(i, t)


assert_equal(i_lab.mode, 'LAB')

k = i_lab.getpixel((0,0))
assert_equal(k, (137,128,128)) # not a linear luminance map. so L != 128

L = i_lab.getdata(0)
a = i_lab.getdata(1)
b = i_lab.getdata(2)

assert_equal(list(L), [137]*100)
assert_equal(list(a), [128]*100)
assert_equal(list(b), [128]*100)


def test_lab_color():
pLab = ImageCms.createProfile("LAB")
Expand All @@ -103,11 +126,11 @@ def test_lab_color():
i = ImageCms.applyTransform(lena(), t)
assert_image(i, "LAB", (128, 128))

i.save('temp.lab.tif')
# i.save('temp.lab.tif') # visually verified vs PS.

target = Image.open('Tests/images/lena.Lab.tif')

assert_image_similar(i, target, 1)
assert_image_similar(i, target, 30)

def test_lab_srgb():
pLab = ImageCms.createProfile("LAB")
Expand All @@ -117,7 +140,9 @@ def test_lab_srgb():

img_srgb = ImageCms.applyTransform(img, t)

assert_image_similar(lena(), img_srgb, 1)
# img_srgb.save('temp.srgb.tif') # visually verified vs ps.

assert_image_similar(lena(), img_srgb, 30)

def test_lab_roundtrip():
# check to see if we're at least internally consistent.
Expand All @@ -130,3 +155,5 @@ def test_lab_roundtrip():
out = ImageCms.applyTransform(i, t2)

assert_image_similar(lena(), out, 2)


0 comments on commit deb424c

Please sign in to comment.