Replacing red with a picture
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:
Code :
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:
Code :
public 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)
}
}
}
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 newPicture
but then that makes a lot of the sample code void and I do not know how to go about changing it.
Re: Replacing red with a picture
I'm not sure what you are trying to do. Is it something like this:
Given an enclosed area that is all one color, you want to replace the pixels in the area of an image with that color with corresponding pixels from an image to give the effect that looks like the new image is behind the image with the the colored area and that the colored area is transparent allowing you to see the new image "through" the area where the color was.
Re: Replacing red with a picture
I tried PMing with the assignement pdf for easier to read directions on what needs to happen. Sorry if it was confusing
Re: Replacing red with a picture
Please post the description and your questions here.
Re: Replacing red with a picture
Nevermind then, thanks anyway
Re: Replacing red with a picture
Please mark the thread as solved if you are done.