Specifications
Intel
®
Image Processing Library Reference Manual
10-4
10
Example 10-1 Conversion to a Bitonal Image
int example101( void ) {
IplImage *imga, *imgb;
const int width = 4, height = 4;
__try {
imga = iplCreateImageHeader(
1, 0, IPL_DEPTH_8U, "GRAY", "GRAY",
IPL_DATA_ORDER_PIXEL, IPL_ORIGIN_TL,
IPL_ALIGN_DWORD, width, height, NULL, NULL,
NULL, NULL);
if( NULL == imga ) return 0;
imgb = iplCreateImageHeader(
1, 0, IPL_DEPTH_1U, "GRAY", "GRAY",
IPL_DATA_ORDER_PIXEL, IPL_ORIGIN_TL,
IPL_ALIGN_DWORD, width, height, NULL, NULL,
NULL, NULL);
if( NULL == imgb ) return 0;
// Create with filling
iplAllocateImage( imga, 1, 3 );
if( NULL == imga->imageData ) return 0;
// Make a spike
((char*)imga->imageData)[7] = (char)7;
iplAllocateImage( imgb, 0, 0 );
if( NULL == imgb->imageData ) return 0;
// This is important. 4 bits occupy 4 bytes
// in the imgb image because of IPL_ALIGN_DWORD
iplThreshold( imga, imgb, 7 );
// Check if an error occurred
if( iplGetErrStatus() != IPL_StsOk ) return 0;
}
__finally {
iplDeallocate(imga, IPL_IMAGE_HEADER | IPL_IMAGE_DATA );
iplDeallocate(imgb, IPL_IMAGE_HEADER | IPL_IMAGE_DATA );
}
return IPL_StsOk == iplGetErrStatus();
}