Shadow

image0

How the image is created

  1. select all blue pixels above a threshold as a mask

  2. create a shadow image that is gray outside and white inside the mask

  3. move the shadow by 20 pixels

  4. copy the shadow onto the white part of the main picture

Note that some blue pixels do not turn white, because changing the threshold would distort the gate too much.


from PIL import Image
import numpy as np

a = np.array(Image.open("bbtor.jpg"))

mask = a[:,:,2] > 180

shadow = np.ones(a.shape, dtype=np.uint8) * 127
shadow[mask] = 255
shadow[20:, 20:] = shadow[:-20, :-20]

a[mask] = shadow[mask]
Image.fromarray(a, 'RGB').save("shadow.png")