For this assignment I have a picture of myself with a green screen background. I have to take this picture of myself and replace the green screen background with another picture (IE: a beach is what I used)
In my picture I am given a red robe to wear. After changing the background I have to replace all the red on the robe with another picture.
I have code that does exactly what I need by replacing the greenscreen background but I do not know how to go about changing the red. This is the code I have so far:
public void chromakey( Picture greenScreen ) { Pixel personsPix; Pixel backgroundPix; int x; x = 0; while( x < this.getWidth() ) { int y; y = 0; while( y < this.getHeight()) { personsPix = this.getPixel(x, y); if(personsPix.getGreen() > (personsPix.getBlue() + personsPix.getRed())) { backgroundPix = greenScreen.getPixel (x, y); personsPix.setColor(backgroundPix.getColor()); } y = y + 1; } x = x + 1; } } public static void main(String[] args) { FileChooser.pickMediaPath(); String fileName = FileChooser.pickAFile(); Picture personPicture = new Picture(fileName); Picture backgroundPicture = new Picture(FileChooser.pickAFile() ); personPicture.chromakey(backgroundPicture); personPicture.explore(); }
Example code was given that shows how to remove red eye from a picture:
Since instead of replacing the red with another color I have to replace it with another picture, the parameter Color newColor means nothing to me. I had an idea to change that parameter to Picture newPicturepublic void removeRedEye(int startX, int startY, int endX, int endY, Color newColor) { Pixel pixel = null; for(int x = startX; x < endX; x++) { for (int y = startY; y < endY; y++) { pixel = getPixel(x,y); if(pixel.colorDistance(Color.red) < 167) pixel.setColor(newColor) } } }
but then that makes a lot of the sample code void and I do not know how to go about changing it.