c++ - Using image as a mask to another -


i beginner opencv , have questions:

how can use 1 image mask image?

for example, have image contains empty circle, , image contains circle content (not empty) , background.

how can extract common parts of 2 images in new image?

i tried extracting pixel pixel (and) operation fails!

can me ideas!

i try following code (that found here) produces wrong result!

i tried binary image replacing

cvscalar bgr = cvscalar(b, g, r); cvset2d(mask, iy+y, ix+x, bgr); 

with

cvscalar bgr = cvscalar(b); cvset2d(mask, iy+y, ix+x, b); 

void processimage(iplimage* mask, iplimage* source, int x, int y) {     int b,g,r;     (int ix=0; ix<source->width; ix++) {         (int iy=0; iy<source->height; iy++) {             //r = cvget2d(source, iy, ix).val[2] * cvget2d(mask, iy, ix).val[2];             //g = cvget2d(source, iy, ix).val[1] * cvget2d(mask, iy, ix).val[1];;             b = cvget2d(source, iy, ix).val[0] * cvget2d(mask, iy, ix).val[0];              cvscalar bgr = cvscalar(b); //, g, r);             cvset2d(mask, iy+y, ix+x, b); //gr);         }     } } 

if understand correctly, have mask (binary image) , want , source image. try this:

cvand(source, source, destination, mask)

that double source there not typo. you're anding source (a no-op), pixels in mask "on" (that is, != 0). note mask must 8-bit single channel image.


Comments