Getting information about a mask

edited December 2014 in How To...

Hi, I would need to know if it's possible to determine whether a specific area of the screen is masked or not. Also, it should be very helpful for me to get information about the boundaries of the mask. Is it possible too?

thank you very much.

Tagged:

Answers

  • To me, a mask is a black and white image that can be used to crop out areas of another image. Is that what you mean by a mask?

    If so, then you should be able to know if a specific point is masked out by checking color of the pixel in the desired position of the mask image.

    You can also use edge-detecting libraries to give you information about the mask too... Check out the OpenCV library & its examples; I believe it does edge detection.

  • Thank you, very much for you kind answer. I suppose I have to use the PImage.get() function. But I'm confused about dealing with transparency (alpha channel). If I get black color on a specified pixel does this mean that the pixel is masked out? Or would I need also the information about alpha channel? In the second case, which function provides the complete ARGB information?

    Thank you again!

  • edited December 2014

    ... which function provides the complete ARGB information?

    Function get() w/ 2 coordinate arguments returns a color type value, which is ARGB:

    Array pixels[] also stores color values:

  • Thank you, guys. I followed your suggestion using get(). The alpha value is 255, means completely opaque. Unfortunately this is not what I expected. Maybe it's better if I provide some details about my work. I have two images (actually I have more, but let's make it simpler), the first image is displayed, then I create a particular mask through an ellipse which makes the second images to be progressively showed as you move the mouse. Basically it works, but in order to go further on my work I need to know which area of the first image has been masked out by the mouse movement. The function get() on the first image always returns 255 (verified with println() ) even on the area which has been masked out. Shouldn't it returns 0 ? Below there is a simplified excerpt of my code. Thank you very much for your any help.

            void setup(){
               PImage image_1 = loadImage("Image_1.jpg");  // first image 
               PImage image_2 = loadImage("Image_2.jpg");  // second image
               PGraphics myMask = createGraphics(width, height);   // mask
    
               image(image_1, 0, 0);   // display first image
            }
    
            void draw(){
                  int size = 50;
    
                  // create mask while moving the mouse
                  myMask.beginDraw();
                  myMask.noStroke();
                  myMask.fill(255);
                  myMask.ellipse(mouseX, mouseY, size, size);
                  myMask.endDraw(); 
    
                  // reveal second image through the created mask
                  image_2.mask(myMask);
                  image(image_2, 0 ,0);
    
                  ...
                 // check if a specific area has been masked out
                 color c = image_1.get(mouseX, mouseY)
                 float a = alpha(c);    // <-- always = 255, even if mouseX and mouseY point to   an
                                                 // area already masked out !!!
    
            }
    
  • color c = image_1.get(mouseX, mouseY);

    Let's say image_1 has the same dimensions as the canvas, you're still checking on the PImage's pixels[].
    And even if you check on the canvas itself, by definition its alpha() is always 255! @-)

  • Ok, clearly I need more study about graphics :) Anyway, is my issue clear enough? Basically I need to know where the mask has been created with the mouse movement. Have you any hints?

  • Maybe you should try get() on image_2 instead. Dunno, sorry! :-S

  • Uhm, maybe you're right. I'll try later and I let you know. Thank you for your support.

Sign In or Register to comment.