Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

ippiAddC_16s_C1RSfs: bug or misunderstanding

cedric_pradalier
Beginner
426 Views
Hi,

I've found what I think is a bug in ippiAddC_16_C1RSfs. I'm running IPP 5.3 on linux, on a Intel Dual Core 2.2GHz. Can someone confirm that my code is correct?

My sample code is:

#include
#include
#include

int main()
{
IppiSize size = {5,5};
Ipp16s A[25], B[25];

unsigned int i,j;
for (j=0;j<5;j++) {
for (i=0;i<5;i++) {
A[j*5+i] = i*j*1024;
printf("%5d ",(int)A[j*5+i]);
}
printf(" ");
}

printf("Plus 2048 ");
ippiAddC_16s_C1RSfs(A,5*sizeof(Ipp16s),2048,
B,5*sizeof(Ipp16s),size,1);

for (j=0;j<5;j++) {
for (i=0;i<5;i++) {
printf("%5d ",B[j*5+i]);
}
printf(" ");
}
return 0;
}


The output is:
0 0 0 0 0
0 1024 2048 3072 4096
0 2048 4096 6144 8192
0 3072 6144 9216 12288
0 4096 8192 12288 16384
Plus 2048
1024 1024 1024 1024 1024
1024 1536 2048 2560 3072
1024 2048 3072 4096 5120
1024 2560 4096 5632 7168
1024 3072 5120 7168 9216


Is this the expected output of this function?
If it is, what is the semantic, and how do I optain a simple addition?

Thanks for your help
0 Kudos
4 Replies
Vladimir_Dudnik
Employee
426 Views

Hello,

I would refer you to IPP manual, volume 2 - Image Processing. Please take a look on chapter 2 - Intel Integrated Performance Primitives - Concepts, Integer Results Scaling topic.

Integer Result Scaling

Some image processing functions operating on integer data use scaling of the internally computed output results by the integer

scaleFactor, which is specified as one of the function parameters. These functions have the Sfs descriptor in their names.

The scale factor can be negative, positive, or zero. Scaling is applied because internal computations are generally performed with a higher precision than the data types used for input and output images.

The scaling of an integer result is done by multiplying the output pixel values by 2

-scaleFactor before the function returns. This helps retain either the output data range or its precision. Usually the scaling with a positive factor is performed by the shift operation. The result is rounded off to the nearest integer number.

For example, the integer

Ipp16s result of the square operation ippiSqr for the input value 200 is equal to 32767 instead of 40000, that is, the result is saturated and the exact value can not be restored. The scaling of the output value with the factor scaleFactor = 1 yields the result 20000 which is not saturated, and the exact value can be restored as 20000*2. Thus, the output data range is retained.

The following example shows how the precision can be partially retained by means of scaling.

The integer square root operation

ippiSqrt (without scaling) for the input value 2 gives the result equal to 1 instead of 1.414. Scaling of the internally computed output value with the factor scaleFactor = -3 gives the result 11, and permits to restore the more precise value as 11*2-3 = 1.375.

Regards,
Vladimir

0 Kudos
cedric_pradalier
Beginner
426 Views
After some trials and errors, I found that putting the scaling parameter to zero produced the expected results.

So maybe it is the naming and/or the documentation of this parameter that is a little unclear.

From my testing it seems that it means how many bits the result pixels are right-shifted of after the addition.


0 Kudos
cedric_pradalier
Beginner
426 Views
Thanks for your help, and for pointing out my mistake :-) I'm impressed by the short answer time.

I still believe that a little cross reference in the manual would help...

I did check the manual before using the function, but kept going with my wrong interpretation of the "Scaling" term without thinking to look it up itself in the manual.
0 Kudos
Vladimir_Dudnik
Employee
426 Views

Thanks, I'll notify team working on documentation about your feedback.

Regards,
Vladimir

0 Kudos
Reply