Take this image of Shia LaBeouf with a green screen behind him from the famous meme where Shia stands in front of a green screen giving a strangely effective motovational speech.
If you haven't seen it, check it out. You'll be glad you did.
Superimpose Shia on the below image of me and friends.
-
Import
pillow
library or Python Image Library must be used to manipulate images on a pixel level. -
Each pixel of the image containing the green screen is parsed and compares RGB value with a threshold in order to determine the 'greenness' of the pixel.
-
Once the 'greenness' of the pixel is determined to be a green screen element, replace the pixel with a corresponding pixel from the background image.
-
After this is repeated for all pixels (Shia LaBeouf image is
509x905
, which means 460,645 pixels), save the image as a standalone. -
The threshold is the heart of the algorithm, therefore outputing the RGB values for each pixel from the Shia LaBeouf image into a CSV could provide insight to an improved algorithm.
-
Voilá, we have our final product. I don't seem to have made the final cut but that's okay.
"Don't let your dreams be dreams!" Shia LaBeouf
Notice a green outline on our hero, Shia LaBeouf, in the final image.
Fine tuning the chroma key algorithm to detect a greater range of greens could result in a cleaner image.
os
for writing our RGB values to find threshold in foreground image.
pillow
or Python Image Library to manipulate images on a pixel level.