%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
In the film industry, it is often necessary to impose actors on top of a rendered background. To do that, the actors are filmed on a "green screen". Here's an example shot (images/greenscreen.jpg
):
Say we'd like to help these folks travel into a forest (skimage/forest.jpg
):
Can you transplant the foreground of the greenscreen onto the backdrop of the forest?
from skimage import io
forest = io.imread('skimage/forest.jpg')
people = io.imread('skimage/greenscreen.jpg')
forest.shape, people.shape
forest = forest[:375, :500, :]
from skimage import img_as_float
forest = img_as_float(forest)
people = img_as_float(people)
print(forest.max(), people.max())
mask = people[..., 1] < 0.7
plt.imshow(mask)
people_selected = people.copy()
#people_selected[mask] = 0
# Should clean up mask a bit here to fill all the holes
from skimage import morphology
mask = morphology.binary_closing(mask, morphology.selem.disk(15))
#mask = morphology.binary_erosion(mask, morphology.selem.disk(5))
plt.imshow(mask)
forest_with_ppl = forest.copy()
forest_with_ppl[mask] = people[mask]
plt.imshow(forest_with_ppl)