Community
cancel
Showing results for 
Search instead for 
Did you mean: 
bibi88
Beginner
26 Views

How to use ippiAddSquare

Hello,

Using ippiAddSquare, I've found a strange behavior. To explain it, here is an example:

src 1 2 3 4 5 6 7 8 9

I was waiting for this result:
dsl 1 4 9 16 25 36 49 64 81

Here is the kind of dst I've acutally received:

1 0 4 0 9 0 16 0 25

More specificaly, here is my code:

IppiSize Roi = {width , height};
Ipp16s* pEdgeVert = ippiMalloc_16s_C1(width, height, &convertWidthStep1);
Ipp32f* pEdgeBorder = ippiMalloc_32f_C1(width, height, &convertWidthStep2);
/* ... processing of pEdgeVert to get some values in /*
ippiSet_32f_C1R(0, pEdgeBorder, width*sizeof(Ipp32f), Roi);
ippiAddSquare_8s32f_C1IR((Ipp8s *) pEdgeVert,width *sizeof(Ipp8s), pEdgeBorder, width *sizeof(Ipp32f),Roi);

Why this code inserts a zero each two column of the expected result?

Thanks in advance!


0 Kudos
5 Replies
Vladimir_Dudnik
Employee
26 Views

Hello,

could you please provide an additional info in order to help us identify the problem: what IPP version do you use, what OS and cpu you were run your test case?

Regards,
Vladimir
bibi88
Beginner
26 Views

Hello,

I'm using IPP 6.1.6.063 on em64t with Ubuntu 64 bits.

Thanks for your help!
Ying_H_Intel
Employee
26 Views

Hi bibi88,

I noticed the EdgeVert are claimed as Ipp 16s *, But when use in the call ippiAddSquare_8s32f_C1IR, it was converted to (Ipp8s*).This may cause the zero in eachelements. is there any specialreason forthe data conversion in your application?

You may use eitherIpp 8s orIPP 16sat both place.

In addition,I'd likerecommend to use stepBytes itself convertWidthStep 1,2 instead of width*sizeof(ipp32f) ,(to avoid potiental error in the future).

Kind Regards,
Ying
bibi88
Beginner
26 Views

Hello Ying,

Thanks for your help!
First of all, I don't use convertWidthStep because it always gives me strange results. Mayeb I don't use it correctly, so here is an example:

int stepGray;
int timeReplicate = 1;
IppiSize Roi = {GrayImg->width, GrayImg->height};
int widthReplicated = GrayImg->width + 2*timeReplicate;
int heightReplicated = GrayImg->height + 2*timeReplicate;
IppiSize RoiReplicated = {widthReplicated, heightReplicated};
Ipp16s* pGray = ippiMalloc_16s_C1(GrayImg->width, GrayImg->height, &stepGray);

ippiConvert_8u16s_C1R(GrayImg->imageData, GrayImg->widthStep*sizeof(Ipp8u), pGray, stepGray, RoiReplicated);


int m,n;
for (m = 0 ; m < 4; m++)
{
for (n = 0 ; n < GrayImg->widthStep ; n++)
{
printf("%d ", GrayImg->imageData[n+m*(GrayImg->widthStep)]);
}
printf("\n");
}
printf("\n\n\n\n");

for (m = 0 ; m < 4; m++)
{
for (n = 0 ; n < stepGray ; n++)
{
printf("%d ", pGray[n+m*(stepGray)]);
}
printf("\n\n");
}

It doesn't give me the same displayed matrix, that's why I don't use it generally.
Secondly, even without the casting or with another cast, I have the same problem (0 between two columns).
If you're kind enough to explain me the problem with stepGray, I will do a simplified version of my code to detail the problem with the zeros.

Thanks!
Ying_H_Intel
Employee
26 Views

Hi Bibi88,

The stepBytes is defined as Distance in bytes between starts of consecutive lines in the source image.
Or you may understand it is the length of onerow, but in Byte

For example, a 4 row and 2 column image, image width=2, image hight=4.

1 2
3 4
5 6
7 8

If use ippiMalloc_xtoallocate memory for the image,
ippiMalloc
Allocates memory aligned to 32-byte boundary for good performance.
then the stepBytesis always a multiple of 32.

SotheconvertWidthStep1/2 is 32. It is not image width 2, not image*sizeof(Ipp16s)=4 or
image*sizeof(Ipp32f)=8 .
the space between 4-32 will be padded with 0.
If print a imagewhich is allocated by ippiMalloc, a pefered solution should be
for (m = 0 ; m < height; m++)
{
for (n = 0 ; n {
printf("%d ", pGray[n+m*(stepGray)/sizeof(Ipp16s)]);
}
printf("\n\n");
}

Forthe value of GrayImg->widthStep,you maymake sure if it is 4-bytes aligned or it is 32-bytes aligned. But printf the image 8u,
for (n = 0 ; n < GrayImg->widthStep ; n++) 'dbetter to change intofor (n = 0 ; n
Icreat asmallexample code for yourreference.

#include
#include "ipp.h"

int main()
{

// Print the version of ipp being used
const IppLibraryVersion* lib = ippiGetLibVersion();
printf("%s %s %d.%d.%d.%d\n", lib->Name, lib->Version,lib->major, lib->minor, lib->majorBuild, lib->build);


/*src 1 2 3 4 5 6 7 8 9

I was waiting for this result:
dsl 1 4 9 16 25 36 49 64 81

Here is the kind of dst I've acutally received:

1 0 4 0 9 0 16 0 25

More specificaly, here is my code:
*/
int width=2;
int height=4;
IppiSize Roi = {width, height};
int convertWidthStep1, convertWidthStep2;
Ipp16s* pEdgeVert = ippiMalloc_16s_C1(width, height, &convertWidthStep1);
Ipp32f* pEdgeBorder = ippiMalloc_32f_C1(width, height, &convertWidthStep2);

int m,n;
Ipp16s temp=1;

printf("the src image\n");
for (m = 0 ; m < height; m++)
{
for (n = 0 ; n < width ; n++)
{
pEdgeVert[n+m*convertWidthStep1/sizeof(Ipp16s)]=temp;
temp++;
printf("%d ", pEdgeVert[n+m*convertWidthStep1/sizeof(Ipp16u)]);

}
printf("\n");

}
printf("\n");

printf("convertWidthStep1 is %d,\t convertWidthStep2 is %d\n ", convertWidthStep1,convertWidthStep2);
printf("image width is %d,\t image width*sizeof(Ipp32f)is %d \n", width,width*sizeof(Ipp32f) );

// ... processing of pEdgeVert to get some values in
ippiSet_32f_C1R(0, pEdgeBorder, convertWidthStep2, Roi);
IppStatus status=ippiAddSquare_16u32f_C1IR((Ipp16u*) pEdgeVert,convertWidthStep1, pEdgeBorder, convertWidthStep2,Roi);
printf("\n%d : %s\n\n", status, ippGetStatusString(status));

printf("the result image\n");
for (m = 0 ; m < height; m++)
{
for (n = 0 ; n < width ; n++)
{
printf("%f ", pEdgeBorder[n+m*convertWidthStep1/sizeof(Ipp32f)]);

}
printf("\n");
}
printf("\n");
return 0;
}

The result,

ippiv8-6.1.dll 6.1 build 137.53 6.1.137.842
the src image
1 2
3 4
5 6
7 8

convertWidthStep1 is 32, convertWidthStep2 is 32
image width is 2, image width*sizeof(Ipp32f)is 8

0 : ippStsNoErr: No error, it's OK

the result image
1.000000 4.000000
9.000000 16.000000
25.000000 36.000000
49.000000 64.000000

Press any key to continue . . .

Regards,
Ying