Lab Color Space

../../_images/anim_lab_rot.png

Animation control:

Visualization Frame Value
Surface geometry constant
Surface position rotation transform per frame
Surface color constant
Shading and highlighting fixed to the coordinate axis
Axis coordinate constant

Based on the static plot from the Color Space example.

To minimize execution time, the Lab surface object was constructed once, then copied for each frame construction. Rotating the copied surface and shading results in ‘stationary viewer’ perception.

import copy
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
import matplotlib.animation as animation
from colorspacious import cspace_converter
import s3dlib.surface as s3d

#.. Lab Surface Rotation Animation

# 1. Define function to examine ....................................

def rgb_to_labCoor(rgb):
    L,a,b = cspace_converter("sRGB1", "CAM02-UCS"  )(rgb.T).T
    return a/80,b/80,L/100

# Setup surface ................................................
rez=6

surface = s3d.CubicSurface().domain([0,1],[0,1],[0,1]).triangulate(rez)
surface.map_color_from_op(lambda xyz : xyz)
surface.map_geom_from_op(rgb_to_labCoor)
surface.transform(scale=2,translate=[0.0,0.0,-1])
surfcopy = copy.copy(surface)

frame = 0
theta = 360*frame
surface.transform(s3d.eulerRot(theta,0)).shade(.5)

# Construct figure, add surface, plot ..........................

fig = plt.figure(figsize=(5,5), facecolor='white')
ax = plt.axes(projection='3d')
minmax,paneColor  = (-1.1,1.1), [.35,.35,.35]
ax.set(xlim=minmax, ylim=minmax, zlim=minmax)
ax.set_facecolor('black')
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
ax.w_xaxis.set_pane_color(paneColor)
ax.w_yaxis.set_pane_color(paneColor)
ax.w_zaxis.set_pane_color(paneColor)

ax.add_collection3d(surface)

fig.tight_layout(pad=0)

# 4. Animation ......................................................

def init_fig():
    return surface,

def update_fig(frame):
    global surface
    ax.collections.remove(surface)

    theta = 360*frame
    surface = copy.copy(surfcopy)
    surface.transform(s3d.eulerRot(theta,0)).shade(.5)

    ax.add_collection3d(surface)

    return surface,

ani = FuncAnimation(fig, update_fig, frames=np.linspace(0, 1, 101),
                    init_func=init_fig, blit=False, repeat=True, interval=100)

print(">>>>>>>>>>>>>>> Animation completed, file save proceeds")
#ani.save('ZZZ.mp4')                                   # use for movie file.
ani.save(None,writer=animation.FFMpegFileWriter())    # use for temp files.
print(">>>>>>>>>>>>>>> Save completed, screen display proceeds")

plt.show()
print(">>>>>>>>>>>>>>> process completed")