how to pull object out of background

edited October 2013 in How To...

I want to pull object out of the background that mean I want to change background of the image. My image is glass of water with a green background. Could you please tell me how to write code to solve this problem. Thank you.

Answers

  • edited October 2013

    Generally, PImage objects are stamped in canvas using image().
    So if your PImage has a full transparent background color, you'll see the 1 determined by canvas's background() instead.

    Now, if your PImage has its own background color, you're gonna need to write a code snippet
    to identify and change it to another value! >:)

    Take a look at pixels[] reference! \m/

  • edited October 2013

    I just start use Processing last week . I don't know about this program work much. Could you please give example of code to me. :D

    I have more question about this problem. How do I write equation to solve this problem of transparent or semi-transparent matting.

  • edited October 2013

    This section is about "Questions about Code". It's supposed that you supply a buggy code for us to find out what's wrong! =:)

  • I am sorry I wrote wrong section :-S

  • Take a look at this tutorial which will help you get started.

    http://processing.org/tutorials/pixels/

  • Thank you for you help. Could you tell me how do write equation to solve this problem of transparent or semi-transparent matting.

  • edited October 2013

    Well, here's my attempt. Be aware that it's not been tested and it's just a snippet.
    It means it's supposed to be used by a more complete program written by you. Good luck! :-bd

    /** 
     * Reset PImage Color (v1.0)
     * by GoToLoop (2013/Oct)
     * 
     * forum.processing.org/two/discussion/188/
     * how-to-pull-object-out-of-background
     */
    
    static final void resetImageColor(PImage img, color c) {
      img.loadPixels();
      final color[] dots = img.pixels;
    
      for (int i = dots.length; i-- != 0;)
        if (dots[i] == c)   dots[i] = 0;
    
      img.updatePixels();
    }
    
  • Thank you very much. I will try to do all my best :D

Sign In or Register to comment.