Mask ROI
A mask region of interest (mask ROI) is specified by another (bitonal) image
pointed to by the maskROI
pointer of the IplImage structure.
Mask ROIs allow an application to determine on a pixel-by-pixel basis whether to perform
an operation. Pixels corresponding to zeros in the mask are not read
(if in a source image) or written (if in the destination image).
Pixels corresponding to 1’s in the mask are processed normally.
The origin of the mask ROI is aligned to the origin of the rectangular ROI
if there is one, or to the origin of the image.
The following example creates a mask image and
applies the blur operation to the corresponding mask ROI.
To run the example from the command line, type:
>roi -t2 -m -o<roioffset> -s<roisize>
The source:
void testMaskROI( IplImage* srcAimg, IplImage* srcBimg, IplImage* dstimg, bool useMaskRoi, int maskRoiOffset, int maskRoiSize ) { IplImage *mask = NULL, *img = NULL; __try { /// create header of a mask image mask = iplCreateImageHeader( 1, // one channel for mask 0, // no alpha channel IPL_DEPTH_1U, // one bit data "GRAY", "GRAY", // it is black and white image here IPL_DATA_ORDER_PIXEL, srcAimg->origin, // the same origin srcAimg->align, // the same align srcAimg->width, srcAimg->height, // the same size of image NULL, NULL, // no roi, no mask NULL, NULL // id, not tiled ); if( !mask ) return; /// create a mask image itself iplAllocateImage( mask, 0, 0 ); if( !mask->imageData ) return; /// construct mask using XOR srcA and srcB iplXor( srcAimg, srcBimg, dstimg ); /// create mask data by using threshold operation. /// Source image for the operation has 3 channels /// so select one of them ipSetROItoWholeImage( dstimg ); dstimg->roi->coi = 1; iplThreshold( dstimg, mask, 0x30 ); /// invert mask iplNot( mask, mask ); /// show mask img ipView( mask, " mask image", !is_modal ); /// create image to operate with mask img = iplCreateImageJaehne( IPL_DEPTH_8U, mask->width, mask->height ); if( !img ) return; /// set mask for the image img->maskROI = mask; /// show source img before blur operation ipView( img, " Jaehne's image", !is_modal ); /// set ROI for the mask image if it is required if( useMaskRoi ) ipSetImageROI( mask, 0, maskRoiOffset,maskRoiOffset, maskRoiSize,maskRoiSize ); /// blur the image with mask and maybe with mask ROI iplBlur( img, img, 5,5, 2,2 ); /// show result ipView( img, "after Blur with mask", is_modal ); } __finally { iplDeallocate( mask, IPL_IMAGE_ALL ); iplDeallocate( img, IPL_IMAGE_ALL ); } }
* Legal Information © 1998-2000, Intel Corporation