I am working on an assignment where I have to remove the background of an image and make the subject of that image get "pasted" on another image as a background. I am trying to remove the background of my dog image, down below with an if statement, but I don't know what to do for it. The background of the dog image is white with the RGB values of (255,255,255).
This is the link to the jungle picture that is fine for now: http://ift.tt/2asADjM
This is the link to the dog image that I am trying to remove the background for: http://ift.tt/2atDXy2
ChromaKey1()
{
Picture pictureObj = new Picture("jungle.png");
pictureObj.explore();
int redValue = 0; int greenValue = 0; int blueValue = 0; int grayValue = 0;
Pixel targetPixel = new Pixel(pictureObj, 0, 0);
Color pixelColor = null;
Color backgroundColor = null;
Pixel pixelObject = null;
for(int y = 0; y < pictureObj.getHeight(); y++)
{
for(int x = 0; x < pictureObj.getWidth(); x++)
{
targetPixel = pictureObj.getPixel(x,y);
pixelColor = targetPixel.getColor();
redValue = pixelColor.getRed();
greenValue = pixelColor.getGreen();
blueValue = pixelColor.getBlue();
targetPixel.setColor(pixelColor);
}
}
pictureObj.explore();
pictureObj.write("newerjungle.jpg");
//pictureObj.show();
Picture pictureObj1 = new Picture("dog.png");
pictureObj1.explore();
for(int y = 0; y < pictureObj1.getHeight(); y++)
{
for(int x = 0; x < pictureObj1.getWidth(); x++)
{
targetPixel = pictureObj1.getPixel(x,y);
pixelColor = targetPixel.getColor();
redValue = pixelColor.getRed();
greenValue = pixelColor.getGreen();
blueValue = pixelColor.getBlue();
if(!(redValue == (255) && greenValue == (255) && blueValue == (255)))
targetPixel.setColor(pixelColor);
}
}
pictureObj1.explore();
pictureObj1.write("dognone1.jpg");
}
Aucun commentaire:
Enregistrer un commentaire