Apply depth image as alpha channel for color image

I premise I am a beginner with OFX and I already searched and found a similar post to this but that solution didn’t seem to work for me.

I am trying to pack depth and color data coming from a KinectV2 into a single ofPixels (RGBA) in order to stream it locally. The data is coming as two ofPixels objects: OF_IMAGE_GRAYSCALE (for depth) and OF_IMAGE_COLOR_ALPHA (for color).

Whats the best way to apply the depth pixels as alpha mask to the color pixels?

I tried to load the pixels into two ofTextures and do ‘colorText.setAlphaMask(depthText)’ that seemed to work but instead of getting the image transparent it started to be transparent on a black background even though my background is red;

I’ll give an example; here I made the background red in order to see if the alpha channel is being applied correctly, and this is the result I got:


(left: grayscale depth map || right: color map with depth map applied as alpha)

You can see how the right image has the red areas which are the initial transparent pixels of the color map, but the in the areas where the depth map should be applying some alpha to the color map, the image shows transparency on black background, instead of being transparent and showing some tone of red.

I am not sure what’s happening, is there anyone that could help me figure this out?

If there is a better solution to achieve this which involves looping through the pixels objects rather than creating textures, that would be even better!

Hi! Could you post a minimal example we could try?

Definitely! I am really just using this fork of ofKinectV2 from @bakercp

First, I simply tried to draw the depth texture as the alpha mask of the color texture in the draw loop:

void ofApp::draw()
{
    //RED BACKGROUND TO CHECK IF ALPHA IS WORKING
    ofBackground(255,0,0,1);
    
   for (int d = 0; d < kinects.size(); d++)
   {
      texRGBRegistered[d].setAlphaMask(texDepth[d]);
      texRGBRegistered[d].draw(0, 0, ofGetWidth(), ofGetHeight());

   }
}

This produced the effect I posted above, transparent colormap on black background even though the background is red.

Might this have something to do with the issue?