Rectangular ROI

A rectangular ROI is a portion of the image or, possibly, the entire image. By default, unless changed by the iplSetROI() function, the entire image is the rectangular region of interest.

In the following example, rectangular ROIs are created for two source images. Then the images' pixel values are added using the iplAdd() function. Note that only the values in the intersection of rectangular ROIs of both input images are actually processed, and only the pixels in the output image's ROI are changed. The library functions align the top left corners of all applicable ROIs in the input and output images. If the rectangular ROI is not specified, the top left corner of the whole image is used. (For a simpler example of using rectangular ROI, see Creating RGB Images.)

To run the example from the command line, type:
>roi -t0 -o<roioffset> -s<roisize>

The source:

void testROI( IplImage* srcAimg, IplImage* srcBimg, IplImage* dstimg,
   int roiOffset, int roiSize )
{
   // create region of interest within srcAimg
   ipSetImageROI( srcAimg,
      0,                      // all channels are of interest
      srcAimg->height / 4,    // x offset of roi
      srcAimg->width / 4,     // y offset of roi
      srcAimg->height / 2,    // width of roi
      srcAimg->width / 2 );   // height of roi
   // Show the ROI location
   iplAddS( srcAimg, srcAimg, 0x40 );
   ipView(srcAimg, "srcA : ROI highlighted", !is_modal );
   /// restore image in roi
   iplSubtractS( srcAimg, srcAimg, 0x40, FALSE );
   // create region of interest within srcBmg : coi,x,y,w,h
   ipSetImageROI( srcBimg, 0, 0,roiOffset, roiSize,roiSize );
   iplAddS( srcBimg, srcBimg, 0x40 );
   ipView( srcBimg, "srcB : ROI highlighted", !is_modal );
   iplSubtractS( srcBimg, srcBimg, 0x40, FALSE );
   // add srcAimg and srcBimg
   iplAdd( srcAimg, srcBimg, dstimg);
   // display result
   ipView( dstimg, "iplAdd srcA and srcB ROIs", is_modal );
}

* Legal Information © 1998-2000, Intel Corporation