Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Replacing red with a picture

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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:
      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:
    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.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    antnas (November 8th, 2012)

  4. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Replacing red with a picture

    Please post the description and your questions here.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Replacing red with a picture

    Nevermind then, thanks anyway

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Replacing red with a picture

    Please mark the thread as solved if you are done.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Red Color glColor4f
    By Lorack in forum AWT / Java Swing
    Replies: 0
    Last Post: July 1st, 2012, 06:21 PM
  2. HELP - placing picture on top of another picture in Java - JLayerPane
    By smasm in forum What's Wrong With My Code?
    Replies: 39
    Last Post: April 27th, 2012, 07:16 PM
  3. Converting a picture made up of 0s and 1s into a colored picture??
    By Kranti1992 in forum Java Theory & Questions
    Replies: 10
    Last Post: November 21st, 2011, 06:25 PM
  4. Getting a red Oval to displayed on screen
    By warnexus in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 13th, 2011, 08:27 PM
  5. How to detect brightest spot among all spots?
    By BharatT in forum Java Theory & Questions
    Replies: 4
    Last Post: February 6th, 2009, 09:12 PM