openCV - finding common fill area / union

hi, just wondering if anyone knows a way of finding a common fill area or union of two images. so finding all the pixels that are white in both images, like applying the & operator.

currently im checking all the pixels in both images and setting the resulting pixels manually.
any chance this is aleady implemented in openCV somewhere?

  
  
void testApp :: checkForCommonFill ( ofxCvGrayscaleImage& imageOut, ofxCvGrayscaleImage& image1, ofxCvGrayscaleImage& image2 )  
{  
	int noPixels;  
	noPixels = imageOut.width * imageOut.height;  
  
	unsigned char* imageOutPixels;  
	unsigned char* image1Pixels;  
	unsigned char* image2Pixels;  
	  
	imageOutPixels	= new unsigned char[ noPixels ];  
	image1Pixels	= image1.getPixels();  
	image2Pixels	= image2.getPixels();  
	  
	for( int i=0; i<noPixels; i++ )  
	{  
		if  
		(   
			image1Pixels[ i ] == 255 &&  
			image2Pixels[ i ] == 255  
		)  
		{  
			imageOutPixels[ i ] = 255;  
		}  
		else  
		{  
			imageOutPixels[ i ] = 0;  
		}  
	}  
	  
	imageOut.setFromPixels( imageOutPixels, imageOut.width, imageOut.height );  
	  
	delete[] imageOutPixels;  
}  
  

it’s cvAnd, and we’ve implemented it in ofxCvImage, by overloading the &= operator. so you should be able to say,

  
imageA &= imageB;  

the same way you can say imageA += imageB, as long as A and B are the same type (grayscale, etc) and same size (imageA.w == imageB.w, etc).

I find it incredibly useful for intersection tests

hope that helps!
zach

that’s perfect, thx!