Channel of Interest (COI)

A COI can be one or all channels of the image. By default, unless the COI is changed by the iplSetROI() function, processing will be carried out on all channels in the image.

The example program on this page uses COIs for constructing one image from another by copying. It copies pixel values from channel 3 in the source image to channel 4 (alpha) in the destination image. Note that only the values within the rectangular ROI are actually copied. (For a simpler example of using COI, see Creating RGB Images.)

You can run the example either from the applet on this page or from the command line:
>roi -t1 -o<roioffset> -s<roisize>

void testCOI( IplImage* srcAimg, IplImage* srcBimg, IplImage* dstimg,
int roiOffset, int roiSize )
{
   IplImage* dstimgRGBA = NULL;
   /// Note that ROI is created in stack and you should not
   /// use the ALL mode in Deallocate function without
   /// setting the image COI to NULL. It is useful to know
   /// but not necessarily to use.
   IplROI roi = { 1, 0,0, width, height };
   __try {
      dstimgRGBA = iplCreateImageHeader(
         4,                    // number of channels
         4,                    // alpha channel number
         IPL_DEPTH_8U,         // depth of data image
         "RGBA", "RGBA",       // color model and channel sequence
         IPL_DATA_ORDER_PIXEL, // image is defined as pixels
         IPL_ORIGIN_TL,        // origin is in the top left corner
         IPL_ALIGN_QWORD,      // image width is aligned 
         width, height,        // width and height of image
         &roi,                 // region of interest
         NULL,                 // no mask ROI here
         NULL, NULL            // image id, not tiled
      );
      if( !dstimgRGBA ) return;
      iplAllocateImage( dstimgRGBA, 1, 128 );
      if( !dstimgRGBA->imageData ) return;
      // Using Channel of Interest, copy one channel at a 
      // time from source to destination for 3 channels.
      ipSetROItoWholeImage( srcAimg );
      ipSetROItoWholeImage( srcBimg );
      /// channels 1 and 2 from source A
      srcAimg->roi->coi = 1;
      dstimgRGBA->roi->coi = 1;
      iplCopy( srcAimg, dstimgRGBA );
      srcAimg->roi->coi = 2;
      dstimgRGBA->roi->coi = 2;
      iplCopy( srcAimg, dstimgRGBA );
      /// channel 3 from source B
      srcBimg->roi->coi = 3;
      ipSetImageROI( dstimgRGBA, 3, roiOffset, roiOffset, roiSize, roiSize );
      iplCopy( srcBimg, dstimgRGBA );
      /// copy channel 3 of source to 
      /// channel 4 (alpha channel) of destination
      dstimgRGBA->roi->coi = 4;
      iplCopy( srcAimg, dstimgRGBA );
      /// destination image RGBA is copy of channels
      ipView( dstimgRGBA, "RGBA is copy of A.1 A.2 B.3 A.3", is_modal );
   }
   __finally {
      /// set roi to NULL to protect 
      /// the automatic variable from freeing
      if( dstimgRGBA) {
         dstimgRGBA->roi = NULL;
         iplDeallocate( dstimgRGBA, IPL_IMAGE_ALL );
      }
   }
}

* Legal Information © 1998-2000, Intel Corporation