Use np.unwrap (same idea as monotonify())

This commit is contained in:
Steven Robertson 2012-01-09 10:17:53 -05:00
parent 728df3ace6
commit 7f745d74cd

View File

@ -347,8 +347,7 @@ class Palette(HunkOCode):
# TODO: premultiply alpha or some nonsense like that? # TODO: premultiply alpha or some nonsense like that?
y, u, v = np.array(cls.YUV * pal.T[:3]) y, u, v = np.array(cls.YUV * pal.T[:3])
uvr = np.hypot(u, v) uvr = np.hypot(u, v)
uvt = np.arctan2(v, u) uvt = np.unwrap(np.arctan2(v, u))
cls.monotonify(uvt)
return y, uvr, uvt, pal.T[3] return y, uvr, uvt, pal.T[3]
@classmethod @classmethod
@ -359,13 +358,6 @@ class Palette(HunkOCode):
# Ensure Fortran order so that the memory gets laid out correctly # Ensure Fortran order so that the memory gets laid out correctly
return np.array([r, g, b, a], order='F').T return np.array([r, g, b, a], order='F').T
@staticmethod
def monotonify(uvt):
"""Eliminate sign-flips in an array of radian angles (in-place)."""
diff = np.diff(uvt)
for i in np.nonzero(np.abs(diff) > np.pi)[0]:
uvt[i:] -= np.sign(diff[i]) * 2 * np.pi
modes = ['hsv', 'yuv', 'yuvpolar'] modes = ['hsv', 'yuv', 'yuvpolar']
decls = "surface<void, cudaSurfaceType2D> flatpal;\n" decls = "surface<void, cudaSurfaceType2D> flatpal;\n"