Skip to content

Instantly share code, notes, and snippets.

@thejayden
Created May 22, 2020 10:18
Show Gist options
  • Select an option

  • Save thejayden/21c7fef13ba38386374c2a7115d3678c to your computer and use it in GitHub Desktop.

Select an option

Save thejayden/21c7fef13ba38386374c2a7115d3678c to your computer and use it in GitHub Desktop.
Green screen algorithm
var fgImage = new SimpleImage("usain.jpg");
var bgImage = new SimpleImage("palm-and-beach.png");
var newImage = new SimpleImage(fgImage.getWidth(),fgImage.getHeight());
for (var fgPx of fgImage.values()){
if (fgPx.getGreen() > 180 && fgPx.getRed()<180 && fgPx.getBlue()<180){
var x = fgPx.getX();
var y = fgPx.getY();
var bgPx = bgImage.getPixel(x,y);
newImage.setPixel(x,y,bgPx);
}
else {
var x = fgPx.getX();
var y = fgPx.getY();
newImage.setPixel(x,y,fgPx);
}
}
print (newImage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment