IppiPyramid with 32f

IppiPyramid with 32f

Hi.Unfotunately, all the examples for Optical flow are using 8u images. The problem I'm having is that the IppiPyramid struct contains 8u Image pointers and I'm using 32f images. I found a threadhttp://software.intel.com/en-us/forums/showthread.php?t=68034&o=a&s=lrthat discusses this; however, the answer is not really helpful.How do I perform optical flow on 32bit images?

	IppiPyramid *pPyr1;

	IppiPyramid *pPyr2;

	IppiOptFlowPyrLK *pOF;
	ippiPyramidInitAlloc (&pPyr1, num_levels, ROI, rate);

	ippiPyramidInitAlloc (&pPyr2, num_levels, ROI, rate);
	IppiPyramidDownState_32f_C1R** pState1 = (IppiPyramidDownState_32f_C1R**)&(pPyr1->pState);

	IppiPyramidDownState_32f_C1R** pState2 = (IppiPyramidDownState_32f_C1R**)&(pPyr2->pState);
	Ipp32f** pImg1 = (Ipp32f**)pPyr1->pImage;

	Ipp32f** pImg2 = (Ipp32f**)pPyr2->pImage;
	int *pStep1 = pPyr1->pStep;

	int *pStep2 = pPyr2->pStep;
	IppiSize *pRoi1 = pPyr1->pRoi;

	IppiSize *pRoi2 = pPyr2->pRoi;
	IppHintAlgorithm hint=ippAlgHintFast;
	int i;

	int level = pPyr1->level;
	ippiPyramidLayerDownInitAlloc_32f_C1R(pState1, ROI, rate, pKernel, kerSize, IPPI_INTER_LINEAR);

	ippiPyramidLayerDownInitAlloc_32f_C1R(pState2, ROI, rate, pKernel, kerSize, IPPI_INTER_LINEAR);
	pImg1[0]  = Img1Ptr; //32f image

	pImg2[0]  = Img2Ptr;//32f image
	pStep1[0] = Img1StepBytes;//32f image

	pStep2[0] = Img2StepBytes;//32f image
	pRoi1[0]  = pRoi2[0] = ROI;
        // error C2440: '=' : cannot convert from 'Ipp32f *' to 'Ipp8u *'

	for (i = 1; i <= level; i++)

	{

	   pPyr1->pImage[i] = (Ipp32f*)ippiMalloc_32f_C1(pRoi1[i].width, pRoi1[i].height, pStep1 + i * sizeof(Ipp32f));

	   pPyr2->pImage[i] = (Ipp32f*)ippiMalloc_32f_C1(pRoi2[i].width, pRoi2[i].height, pStep2 + i * sizeof(Ipp32f));

	   ippiPyramidLayerDown_32f_C1R(pImg1[i-1], pStep1[i-1], pRoi1[i-1], pImg1[i], pStep1[i], pRoi1[i], *pState1);

	   ippiPyramidLayerDown_32f_C1R(pImg2[i-1], pStep2[i-1], pRoi2[i-1], pImg2[i], pStep2[i], pRoi2[i], *pState2);

	}
I've tried to simply cast the pointers to 32f but I'm getting an error. If I just cast that to Ipp8u, the memory location should still be the same which should fix the error. How do I setpStep1?? Would it not be set to 8u spacing byippiPyramidInitAlloc?

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

ippiPyramidLayerDown_32f_C1R(pImg2[i-1], pStep2[i-1], pRoi2[i-1], pImg2[i], pStep2[i], pRoi2[i], *pState2);This is returning ippStsStepErr = -14, /* Step value is not valid. */

Hi Ryan,

You can refer to the example code in IPP reference manual, which is using ippiRyramid with 32f.
Example14-6 shows how different general pyramids functions can be used to create the Gaussian and Laplacian pyramids: ( I attached it at the end of message).

For example, please note the code i mark as Bold.
1) Regarding "The IppiPyramid contains pointers to 8 bit unsigned Images", Please see the structure,
typedef struct _IppiPyramid {
Ipp8u **pImage;
IppiSize *pRoi;
Ipp64f *pRate;
int *pStep;
Ipp8u *pState;
int level;
} IppiPyramid;

Here the pionteris actually ** pointer. And the cost happen in
Ipp32** pImg1 = (Ipp32f**)pPyr1->pImage;
Ipp32f** pImg2 = (Ipp32f**)pPyr2->pImage;

And then use the pointer array pImg1[] instead of pPyr1->pImage.

for (i = 1; i <= level; i++)
{
pImg1[i] = ippiMalloc_32f_C1(pRoi1[i].width, pRoi1[i].height, pStep1 + i);//(Ipp32f*)
pImg2[i] = ippiMalloc_32f_C1(pRoi2[i].width, pRoi2[i].height, pStep2 + i);//(Ipp32f*)
sts = ippiPyramidLayerDown_32f_C1R(pImg1[i-1], pStep1[i-1], pRoi1[i-1], pImg1[i], pStep1[i], pRoi1[i], *pState1);
sts = ippiPyramidLayerDown_32f_C1R(pImg2[i-1], pStep2[i-1], pRoi2[i-1], pImg2[i], pStep2[i], pRoi2[i], *pState2);
}

Regarding the wrong steps, as pStep1 is a pointer, The address ofpStep1[1]=pStep+1 (not related to imagedatatype)

After change the two place, you will get your code work.

Best Regards,
Ying

Example of Using General Pyramid Functions

The following Example14-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);
} 

Thank you Ying!

Login to leave a comment.