Movie Magic Spoiler Alert – Bluescreen

bluescreenIf you are someone who enjoys the wonder of movie-making without the desire to know how it works then read no further. Nick Parlante’s week 3 lecture revealed how the bluescreen/greenscreen trick uses computer code to insert portions of one image onto another. I have always wondered why that works and now I know.

The concept of pixels having a Red, Green, and Blue value is the foundation of this trick. The reason movie studios have those Green or Blue screens on studio is because it allows the computer to easily detect the color of the pixels from the screen and then replace them with pixels from another image.

In code language you need a way to identify which pixels to replace by identifying the Blue or Green ones. This is done by writing code that finds out the number of the Red, Green, and Blue portions of each pixel (remember that they range from 0-255) and finding the average. Comparing the average value of a pixel’s three numbers against a high Green value allows the computer to identify which pixels to replace with pixels from the other image.

Here are some of the key code components:

Commands like pixel.getX() to find the x (or y) coordinates within an image;

if statement to identify which of the green pixels are to be replaced by finding pixels where the Green value is higher than “avg” which is the average of the three color values.

if (pixel.getGreen() >  avg)

Link the pixel from one image to the other using names to represent each image (“image” and “back”)

pixel2 = back.getPixel(pixel.getX(), pixel.getY())

and copying the color values of the other image, pixel2, to the corresponding original “pixel” on the green screen.

pixel.setRed(pixel2.getRed())

This process done on every individual image in a video which is really just a large amount of static images flicking by rapidly.

[Image courtesy of mvjantzen]

Advertisements
This entry was posted in Digital Images, Programming and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s