Specifications
Linear Image Transforms
7-11
7
Example 7-2 Computing the DCT of an Image (continued)
// Create without filling
iplAllocateImage( imga, 0,0 );
if( NULL == imga->imageData ) return 0;
// Fill by sample data
for( i=0; i<width*height; i++)
((char*)imga->imageData)[i] = (char)(i+1);
iplAllocateImage( imgb, 0, 0 );
if( NULL == imgb->imageData ) return 0;
iplDCT2D( imga, imgb, IPL_DCT_Forward );
// Now there are (width+height-1) DCT coefficients
for( y=1; y<height; y++)
for( x=1; x<width; x++)
((short*)imgb->imageData)[y*width+x]= (short)0;
// Restore source image from some DCT coefficients
iplDCT2D( imgb, imga, IPL_DCT_Inverse );
// Check if an error occurred
if( iplGetErrStatus() != IPL_StsOk ) return 0;
}
__finally {
iplDCT2D( NULL, NULL, IPL_DCT_Free );
iplDeallocate(imga,IPL_IMAGE_HEADER|IPL_IMAGE_DATA);
iplDeallocate(imgb,IPL_IMAGE_HEADER|IPL_IMAGE_DATA);
}
return IPL_StsOk == iplGetErrStatus();
}