ippiFilterGauss calculates wrong results.

ippiFilterGauss calculates wrong results.

Hello.

I've tried to work with that function. But it gives results different from the Matlab results. Moreover, if I apply the filter to matrix every elements is 1 it gives something strange.

I'm novice. May you give me links to samples. Really working samples.

Thank you.

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

for example.

const Ipp8u nSize9 = 9, nSize8 = 9;
// IPP test
Ipp32f src[nSize9 * nSize8] = {
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1

//0, 1, 2, 3, 4, 5, 6, 7, 0,
//1, 2, 3, 4, 5, 6, 7, 0, 1,
//2, 3, 4, 5, 6, 7, 0, 1, 2,
//3, 4, 5, 6, 7, 0, 1, 2, 3,
//4, 5, 6, 7, 0, 1, 2, 3, 4,
//5, 6, 7, 0, 1, 2, 3, 4, 5,
//6, 7, 0, 1, 2, 3, 4, 5, 6,
//7, 0, 1, 2, 3, 4, 5, 6, 7,
//0, 1, 2, 3, 4, 5, 6, 7, 0

};
Ipp32f dst[nSize8*nSize9] = {0};
IppiSize roiSize = {nSize9, nSize8 };

ippiFilterGauss_32f_C1R ( src, nSize8 * sizeof (Ipp32f)
, dst, nSize8* sizeof (Ipp32f)
, roiSize, ippMskSize5x5 );

for (int i = 0 ; i < roiSize.width; i++)
{
for (int j = 0; j < roiSize.height; j++)
{
printf (TEXT ("%7.4f, "), src[i*roiSize.height + j]);
}

printf (TEXT("\t\t"));

for (int j = 0; j < roiSize.height; j++)
{
printf (TEXT ("%7.4f, "), dst[i*roiSize.height + j]);
}

printf (TEXT("\n"));

}

Result are

-12034934.0000, -2256549.5000, 0.7233, 0.7233, 0.7233, -1316320.1250, -7145741.0000, -15607804.0000, -15607804.0000,
-7145741.0000, -1316319.8750, 0.9475, 0.9475, 0.9475, -376090.7188, -1692411.6250, -3572870.0000, -3572870.0000,
-1692411.6250, -376090.6563, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, -376090.6563, -1692411.6250,
-3572870.0000, -3948961.7500, -3384824.0000, -3948961.7500, -3948961.7500, -3384824.0000, -4325053.0000, -6581603.0000, -12787116.0000,
-21249180.0000, -22565502.0000, -19932858.0000, -22565502.0000, -22565502.0000, -19932858.0000, -23881822.0000, -30651472.0000, -41746176.0000,

Sorry. Double comment. Deleted.

Hi,

Have you read a chapter in IPP manual devoted to ROI concept? With mask 5x5 you have to provide 2 pixels wide border in the memory. You can use ippiCopyReplicateBorder for this purpose or shift pSrc to the 3rd pixel in the 3rd row and provide smaller roi (width-4 and height-4). All functions that reconstruct borders have "border" suffix, for all other you should care about providing border pixels yourself.

regards, Igor

Thank you for replay.

I've done as you said, but anyway results are wrong (value 1. in ROI where must be values of filtering). I'm using trial version. Is it possible that the reason in it?

const int nWidth = 15, nHeight = 9;

IppiSize nOffset = {2, 2};

IppiSize nsWhole = { nHeight, nWidth};
Ipp32f faSrc[nWidth * nHeight];
Ipp32f* pSrcStart = &faSrc[nOffset.width * nHeight + nOffset.height];

 

IppStatus nError = ippiSet_32f_C1R (1., faSrc, nHeight*sizeof(Ipp32f), nsWhole);

 

PrintArray("Src", faSrc, nWidth, nHeight, NULL);

 

Ipp32f faDst[nWidth*nHeight];
Ipp32f* pDstStart = &faDst[nOffset.width * nHeight + nOffset.height];

 

nError = ippiSet_32f_C1R (0., faDst, nHeight*sizeof(Ipp32f), nsWhole);

 

PrintArray("Dst", faDst, nWidth, nHeight);

 

IppiSize nRoiSize = {4, 6};

 

nError = ippiFilterGauss_32f_C1R (pSrcStart, nHeight * sizeof(Ipp32f)
, pDstStart, nHeight * sizeof(Ipp32f)
, nRoiSize
, ippMskSize5x5);

PrintArray ("AfterGauss", faDst, nWidth, nHeight, &nOffset);

Hi,

trial version doesn't have any limitations on functionality/optimization. What is wrong for you now? You see different output from Matlab and IPP? Which sigma/stddev do you use for Matlab? ippiFilterGauss is fixed filter - it means that it uses predefined coefficients (as described in the manual):

This function applies a lowpass Gaussian filter to an image ROI. The corresponding kernel is the matrix of either 3x3 or 5x5 size. The 3x3 filter uses the kernel:

1/16 2/16 1/16

2/16 4/16 2/16

1/16 2/16 1/16

These filter coefficients correspond to a 2-dimensional Gaussian distribution with standard deviation 0.85. The 5x5 filter uses the kernel:

2/571 7/571 12/571 7/571 2/571

7/571 31/571 52/571 31/571 7/571

12/571 52/571 127/571 52/571 12/571

7/571 31/571 52/571 31/571 7/571

2/571 7/571 12/571 7/571 2/571

These filter coefficients correspond to a 2-dimensional Gaussian distribution with standard deviation 1.0.

If you need another sigma/stddev - please use ippiFilterGaussBorder_32f_C1R - it has sigma as a parameter:

IPPAPI(IppStatus, ippiFilterGaussBorder_32f_C1R, (const Ipp32f* pSrc, int srcStep,Ipp32f* pDst, int dstStep,
                                           IppiSize roiSize,int KernelSize,Ipp32f sigma,
                                           IppiBorderType borderType, Ipp32f borderValue,
                                           Ipp8u* pBuffer))
feel free to address any other questions/concerns,

regards, Igor

Hi M a. 

What is the error  you are seeing in ROI?   I review your code,  just a little naming problem.  

nWidth=15, nHeight=9.   and  as we understand, the image's Width is 15, thus all of row steps is 15 *sizeof(Ipp32f).  You use nHeight in the code. The result should correct.  but this may bring confusion.

I use the widths is 9 and height is 15 and get the below result. 

All value in ROI (start from point (2, 2), size is (4 width,  6 heigh). are 1. Other value is 0. 

Best Regards

Ying 

 

 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
 1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00    1.00
AfterGauss
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    1.00    1.00    1.00    1.00    0.00    0.00    0.00
 0.00    0.00    1.00    1.00    1.00    1.00    0.00    0.00    0.00
 0.00    0.00    1.00    1.00    1.00    1.00    0.00    0.00    0.00
 0.00    0.00    1.00    1.00    1.00    1.00    0.00    0.00    0.00
 0.00    0.00    1.00    1.00    1.00    1.00    0.00    0.00    0.00
 0.00    0.00    1.00    1.00    1.00    1.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
 0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00

SoHi, Igor

If you need another sigma/stddev - please use ippiFilterGaussBorder_32f_C1R - it has sigma as a parameter:

Thanks for information about a way to change sigma. It is useful.

trial version doesn't have any limitations on functionality/optimization.

Good, it's mean that the problem in my code or my understanding of IPP.

What is wrong for you now? You see different output from Matlab and IPP? Which sigma/stddev do you use for Matlab? ippiFilterGauss is fixed filter - it means that it uses predefined coefficients (as described in the manual):

Problem is that the FilterGauss gives same value as in ROI of the source array . For example, results of previous code

Src:
0 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
1 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
2 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
3 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
4 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
5 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
6 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
7 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
8 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
9 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
10 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
11 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
12 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
13 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,
14 - 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54, 2.54,

Dst:
0 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
1 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
2 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
3 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
4 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
5 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
6 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
7 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
8 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
9 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
10 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
11 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
12 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
13 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
14 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,

AfterGauss:
0 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
1 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
2 - 0.00, 0.00, 2.54, 2.54, 2.54, 2.54, 0.00, 0.00, 0.00,
3 - 0.00, 0.00, 2.54, 2.54, 2.54, 2.54, 0.00, 0.00, 0.00,
4 - 0.00, 0.00, 2.54, 2.54, 2.54, 2.54, 0.00, 0.00, 0.00,
5 - 0.00, 0.00, 2.54, 2.54, 2.54, 2.54, 0.00, 0.00, 0.00,
6 - 0.00, 0.00, 2.54, 2.54, 2.54, 2.54, 0.00, 0.00, 0.00,
7 - 0.00, 0.00, 2.54, 2.54, 2.54, 2.54, 0.00, 0.00, 0.00,
8 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
9 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
10 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
11 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
12 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
13 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
14 - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,

It confuses me. Actually, It must give something different. Could you launch the above code and look to results?

regards,

Mark

Are deprecated functions (FilterGauss, ConvFull) still available in 7.1.1?

Are deprecated functions (FilterGauss, ConvFull) still available in 7.1.1?

Hi.

All value in ROI (start from point (2, 2), size is (4 width, 6 heigh). are 1. Other value is 0. 

Similar test in Matlab gives a different result. Actually, Gauss filter just multiplicates elements of one matrix to other and collects it. Finally, something like this

h(k,l) = sumi(sumj(src1(i,j)*src2(k-j,l-i)

where src1 - is given by user, src2 - is Gauss filter matrix (ippMskSize5x5/ippMskSize3x3  != 1). So, I've wondered why we have got value 1 in ROI?

Sorry, for my english.

I need the IPP library's functionality and, at the moment, test the trial version of it. And I'm going to buy the library if it will be ok for me.

Same confusing situation I have in test of ConvFull. I cannot get right values for test data, calculated in Matlab and manually.

Could you help me?

regards,

Mark.

Mark,

1) please provide your Matlab code, input and output (for Gaussian)

2) the same for ConvFull - your C code and your Matlab code

without these things I can't help you; none from deprepecated functions has been removed yet even in coming soon IPP 8.1

regards, Igor

Gauss filtering.

Matlab code:

fSrc = ones (15, 9, 'double');

hGauss = fspecial ('gaussian', [5 5], 0.85)

sDst = imfilter (fSrc, hGauss);

See above for C code.

 

Convolution

Matlab:

fSrc = [1., 1., 2., 5., 10., 10., 13., 21., 15., 18., 22., 22., 22.];
hKernel = [1., 4., 1.];
fDst = conv2(fSrc, hKernel);

C code:

printf ("Test of ConvFullXXX function.\n----------------\n");
const int nSrcWidth = 11;
const int nKernelWidth = 3;

const IppiSize nKernelSize = {1, nKernelWidth};
const IppiSize nSrcSize = {1, nSrcWidth};

Ipp32f Src[nSrcWidth] = {1, 1, 2, 5, 10, 10, 13, 21, 15, 18, 22, 22, 22};

Ipp32f Kernel3[nKernelWidth] = {1, 4, 1};

Ipp32f Dest[nSrcWidth + nKernelWidth ] = {0};

 

IppStatus nError = ippiConvFull_32f_C1R (Src+1 , nSrcWidth * sizeof(Ipp32f) , nSrcSize
                                                            , Kernel3, nKernelWidth * sizeof(Ipp32f) , nKernelSize
                                                            , Dest , (nSrcWidth + nKernelWidth)*sizeof(Ipp32f));

 

PrintArray ("Result", Dest, 1, nSrcWidth + nKernelWidth);

 

 

I've found the problems:

Wrong dimensions for source/destination arrays and ROI;  

FilterGauss/ConvFull don't work for 1-dimensional arrays (for them is applicable only ippsFilterGauss/ippsConv form Signal's domain.).

Wrong border values.

Thank you for all, who answer to my questions.

Mark

 

I've found the problems:

Wrong dimensions for source/destination arrays and ROI;  

FilterGauss/ConvFull don't work for 1-dimensional arrays (for them is applicable only ippsFilterGauss/ippsConv form Signal's domain.).

Wrong border values.

Thank you for all, who answer to my questions.

Mark

 

I've found the problems:

Wrong dimensions for source/destination arrays and ROI;  

FilterGauss/ConvFull don't work for 1-dimensional arrays (for them is applicable only ippsFilterGauss/ippsConv form Signal's domain.).

Wrong border values.

Thank you for all, who answer to my questions.

Mark

 

The C and Matlab code

C Code:
// simple filtergauss
printf ("Test of FilterGaussBorderXXX.\n----------------\n");
const int nWidth = 9, nHeight = 8;
const int nKernelWidth = 5;
IppiSize nOffset = {0, 0};

IppiSize nsWhole = { nWidth, nHeight};
IppiSize nsMiddleRoi = {4, 4};
IppiSize nsPart = {4, 3};

IppStatus nError;

Ipp32f faSrc[nWidth * nHeight] = {1};
nError = ippiSet_32f_C1R (1, faSrc, nWidth*sizeof(Ipp32f), nsWhole);
nError = ippiSet_32f_C1R (2, faSrc + 2 * nWidth + 3, nWidth*sizeof(Ipp32f), nsMiddleRoi);
//ippiSet_32f_C1R (0, faSrc, nHeight * sizeof (Ipp32f), nsFirstHalf);
PrintArray("Src", faSrc, nWidth, nHeight, NULL);

IppiSize nRoiSize = {nWidth,nHeight};

Ipp32f faDst[nWidth * nHeight];

nError = ippiSet_32f_C1R (0., faDst, nWidth*sizeof(Ipp32f), nRoiSize);
PrintArray("Dst", faDst, nWidth, nHeight);

int nBufferSize = 0;
ippiFilterGaussGetBufferSize_32f_C1R (nRoiSize, 5, &nBufferSize);
Ipp8u* pBuffer = (Ipp8u*) malloc (nBufferSize);

nError = ippiFilterGaussBorder_32f_C1
(faSrc, nWidth * sizeof(Ipp32f)
, faDst, nWidth * sizeof(Ipp32f)
, nRoiSize
, nKernelWidth, 0.85, ippBorderRepl, 1
, pBuffer);

free (pBuffer);

PrintArray ("AfterGauss", faDst, nRoiSize.width, nRoiSize.height, &nOffset);

Matlab Code:

fSrc = ones( 8, 9, 'double');
fSrc(3:6, 4:7) = 2;
fKernel = fspecial ('gaussian', [5 5], 0.85);
fDst = imfilter (fSrc, fKernel, 'replicate');

  

 

 

Great to know that you've managed to solve all the issues yourself. Feel free to ask in case of any other problems.

regards, Igor

Leave a Comment

Please sign in to add a comment. Not a member? Join today