def xyz_to_lab(x, y, z, *rest): # see http://www.brucelindbloom.com/Eqn_XYZ_to_Lab.html xyz = array([u / v for u, v in zip([x, y, z], _ref_white.xyz)]) x, y, z = map(_scale_xyz_to_lab, xyz) # MMA scales by 1/100 return ((1.16 * y) - 0.16, 5. * (x - y), 2. * (y - z)) + rest
def _checkImageConversion(self, size, convert): pixels = [[random(), random(), random()] for _ in range(size * size)] refs = [convert(p) for p in pixels] image = [[pixels[x * size + y] for y in range(size)] for x in range(size)] image = convert(array(image)) for x in range(size): for y in range(size): p1 = image[x][y] p2 = refs[x * size + y] self.assertEqual(len(p1), len(p2)) for a, b in zip(p1, p2): self.assertAlmostEqual(a, b, 12)
def testConditionalComplex(self): a = array([[[1, 2], [4, 5]], [[7, 8], [10, 11]]]) a = vectorize(a, 0, _test_complex_conditional) self.assertEqualArrays(a, [[[-1, -1], [40, 50]], [[70, 80], [100, 111]]])
def testSimpleConditional(self): a = array([[[0.1, 0.6], [1.8, 0.4]], [[-0.1, -0.8], [1.1, 0.5]]]) a = vectorize(a, 0, _test_simple_conditional) self.assertEqualArrays( a, [[[-0.1, 1.6], [2.8, -0.4]], [[0.1, 0.8], [2.1, -0.5]]])
def testMod(self): self.assertEqualArrays( mod(array([[10, 20], [30, 40]]), [[7, 7], [7, 7]]), [[3, 6], [2, 5]])
def testClip(self): a = array([[[-0.1, 0.6], [-1.8, -0.4]], [[0.1, 0.8], [1.1, 0.5]]]) a = clip(a, 0, 1) self.assertEqualArrays( a, [[[0., 0.6], [0., 0.]], [[0.1, 0.8], [1., 0.5]]])
def testSimpleConditional(self): a = array([[[0.1, 0.6], [1.8, 0.4]], [[-0.1, -0.8], [1.1, 0.5]]]) a = vectorize(a, 0, _test_simple_conditional) self.assertEqualArrays(a, [[[-0.1, 1.6], [2.8, -0.4]], [[0.1, 0.8], [2.1, -0.5]]])
def testMod(self): self.assertEqualArrays(mod(array([[10, 20], [30, 40]]), [[7, 7], [7, 7]]), [[3, 6], [2, 5]])
def testClip(self): a = array([[[-0.1, 0.6], [-1.8, -0.4]], [[0.1, 0.8], [1.1, 0.5]]]) a = clip(a, 0, 1) self.assertEqualArrays(a, [[[0., 0.6], [0., 0.]], [[0.1, 0.8], [1., 0.5]]])