Thursday, April 22, 2010

Proof of Concept: Snowcrash Effect

Here we go.

Using FFMPEG and Netpbm in Cygwin I created an effect that turned out very close to what I had in mind. With more time I can clean the images up, and I probably need different film footage with more consistent lighting. Anyway I'm very proud of what I produced, which is an original effect that has probably been done before but while I searched, it was to be ungooglable.

I started with two versions of my video footage, one with the green masked out and the other with red masked out. To create the mask I converted the selected brightness of red and green to blue and red respectively. This was done to avoid too much of the image to be masked and gave me more control in this aspect.

With the red masked out, I placed the subject in video footage into the first background which was the garage. I then created a mask from the green and applied it to the second background which was the dojo and ninja suit. I merged the two and created an animated video which shows the figure in the garage, then the original background is pulled off of everything around him to leave him standing as a ninja training in a dojo.





#!/bin/bash

# create folders for images

mkdir blueconvert

mkdir bluemasked

mkdir RedImages

mkdir maskinvert

mkdir merged

mkdir Snowcrashed

mkdir GreenImages

mkdir FinalMerge

mkdir GreenMask

mkdir greenconvert


# extract images from Original video file

echo "Extracting Images"

ffmpeg -i RedFootage.avi -f image2 RedImages/%d.ppm

ffmpeg -i GreenFootage.avi -f image2 GreenImages/%d.ppm



# Take wanted red from all images Blue for mask

echo "Turn Red To Blue"

FILES=RedImages/*.ppm
b=1

for i in $FILES

do

ppmchange -closeness=29 red blue RedImages/$b.ppm >blueconvert/$b-blue.ppm
let b=$b+1
done

# Take all the blue and mask it out

echo "Make mask out of blue"

FILES2=blueconvert/*-blue.ppm
c=1

for i in {1..76}

do

ppmcolormask -color blue blueconvert/$c-blue.ppm >bluemasked/$c-masked.pbm
let c=$c+1
done

# Invert the color mask

echo "Inverting Mask"

FILES3=bluemasked/*-masked.pbm
d=1

for i in {1..76}

do

pnminvert bluemasked/$d-masked.pbm >maskinvert/$d-maskinvert.pbm
let d=$d+1
done

# Merge the background with the foreground

echo "Merging Images"

FILES4=maskinvert/*-maskinvert.pbm
e=1

for i in {1..76}

do

pamcomp background/FirstBackground.ppm RedImages/$e.ppm -alpha=maskinvert/$e-maskinvert.pbm >merged/$e.ppm

pamcomp background/FirstBackground.ppm RedImages/$e.ppm -alpha=maskinvert/$e-maskinvert.pbm >FinalMerge/$e.ppm

let e=$e+1
done

# Take wanted green from all images Red for mask

echo "Turn Green To Red"

FILES=GreenImages/*.ppm
z=1

for i in {1..76}

do

ppmchange -closeness=40 green red GreenImages/$z.ppm >greenconvert/$z-green.ppm
let z=$z+1
done

# Create Mask for Green Image

echo "Creating Mask for Green Image"

FILES5=greenconvert/*-green.ppm
f=1

for i in {1..76}

do

ppmcolormask -color red greenconvert/$f-green.ppm >GreenMask/$f-masked.pbm
let f=$f+1
done

# Apply Green Masked to the merged images

echo "Applying Green Mask to Images"

FILES6=GreenMask/*-masked.pbm
g=1
h=26

for i in {1..76}

do

pamcomp background/FinalBackground.ppm merged/$g.ppm -alpha=GreenMask/$g-masked.pbm >FinalMerge/$h.ppm
let g=$g+1
let h=$h+1
done

#convert manipulated images into a video

echo "Creating Video"

ffmpeg -f image2 -i FinalMerge/%d.ppm Snowcrashed/SnowcrashedOutput.avi

No comments:

Post a Comment