Example of Using General Pyramid Functions

The following Example 14-6 shows how different general pyramids functions can be used to create the Gaussian and Laplacian pyramids:

Building Gaussian and Laplacian Pyramids  

void UsePyramids(Ipp32f *pSrc, IppiSize srcRoi, int srcStep, Ipp32f *pkernel, int kerSize) {
 float rate = 2.0f;
 IppiPyramid *gPyr; // pointer to Gaussian pyramid structure
 IppiPyramid *lPyr; // pointer to Laplacian pyramid structure
 // allocate pyramid structures
 ippiPyramidInitAlloc (&gPyr, 1000, srcRoi, rate);
 ippiPyramidInitAlloc (&lPyr, 1000, srcRoi, rate);
 {
   int i;
   IppiPyramidDownState_32f_C1R **gState = (IppiPyramidDownState_32f_C1R**)&(gPyr->pState);
   IppiPyramidUpState_32f_C1R **lState = (IppiPyramidUpState_32f_C1R**) &(lPyr->pState);
   Ipp32f **gImage = (Ipp32f**)(gPyr->pImage);
   Ipp32f **lImage = (Ipp32f**)(lPyr->pImage);
   IppiSize *pRoi = gPyr->pRoi;
   int *gStep = gPyr->pStep;
   int *lStep = lPyr->pStep;
   int level = gPyr->level;
   Ipp32f *ptr;
   int step;
   // allocate structures to calculate pyramid layers
   ippiPyramidLayerDownInitAlloc_32f_C1R
                          (gState, srcRoi, rate, pkernel, kerSize, IPPI_INTER_LINEAR);
   ippiPyramidLayerUpInitAlloc_32f_C1R 
                          (lState, srcRoi, rate, pkernel, kerSize, IPPI_INTER_LINEAR);
   // build Gaussian pyramid with level+1 layers
   gImage[0] = pSrc;
   gStep[0] = srcStep;
   for (i=1; i<=level;i++) {
     gImage[i] = ippiMalloc_32f_C1(pRoi[i].width,pRoi[i].height,gStep+i);
     ippiPyramidLayerDown_32f_C1R
                (gImage[i-1], gStep[i-1], pRoi[i-1], gImage[i], gStep[i], pRoi[i], *gState);
   }
   // build Laplacian pyramid with level layers
   ptr = ippiMalloc_32f_C1(srcRoi.width,srcRoi.height,&step);
   for (i=level-1; i>=0; i--) {
     lImage[i] = ippiMalloc_32f_C1(pRoi[i].width,pRoi[i].height,lStep+i);
     ippiPyramidLayerUp_32f_C1R(gImage[i+1], gStep[i+1], pRoi[i+1], ptr, step, pRoi[i], *lState);
     ippiSub_32f_C1R(ptr, step, gImage[i], gStep[i], lImage[i], lStep[i], pRoi[i]);
   }
   ippiFree(ptr);
   ippiPyramidLayerDownFree_32f_C1R(*gState);
   ippiPyramidLayerUpFree_32f_C1R(*lState);



   // use Gaussian and Laplacian pyramids
   // free allocated images
   for (i=1; i<=level; i++) {
          ippiFree(gImage[i]);
          ippiFree(lImage[i-1]);
   }
 }
 //  free pyramid structures
 ippiPyramidFree (gPyr);
 ippiPyramidFree (lPyr);
} 




Submit feedback on this help topic

Copyright © 2000 - 2011, Intel Corporation. All rights reserved.