Project DelphiTensors Workshop

Grayscale as a contraction

Converting a colour image to grayscale is a contraction of the colour axis against three weights.

w = np.array([0.2125, 0.7154, 0.0721]) # RGB -> grayscale weights gray = np.einsum('hwc,c->hw', photo, w) # (512, 512)

The three colour values of each pixel are multiplied by the three weights and summed to one number. The colour axis disappears because c is not after the arrow.