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

Bilateral Filter

gkguru
Beginner
884 Views
Hi,

I am having a little trouble understanding and initializing bilateral filter.

First of all, can anyone explain what the argument 'stepInKernel' in the method FilterBilateralInit mean?
Also, how does one initialize the IppiFilterBilateralSpec structure/allocate external buffer? The information provided in the manual is a bit confusing.

I get a run time error when running this piece of code.

status = ippiFilterBilateralGetBufSize_8u_C1R(ippiFilterBilateralGauss, imgSize, kernelSize, &buffer);
pSpec = (IppiFilterBilateralSpec*)malloc(buffer);
status = ippiFilterBilateralInit_8u_C1R(ippiFilterBilateralGauss, kernelSize, 1.0, 1.0, stepInKernel, pSpec);
status = ippiFilterBilateral_8u_C1R(srcGrayImg, srcGrayStep, dstGrayImg,dstGrayStep,imgSize, kernelSize, pSpec);

Thanks
Guru

0 Kudos
10 Replies
gkguru
Beginner
884 Views
By bad...Forgot to add borders. So the filter is now working.

But I still dont know what stepInKernel - "Processing" step in the filter kernel means?


Thanks
Guru

0 Kudos
malikcoates
Beginner
884 Views
I'd also like an answer to this. The stepInKernel parameter seem to be undocumented.
0 Kudos
Ivan_Z_Intel
Employee
884 Views

The filter processes only the pixels what have the kernel coordinates multiple of stepInKernel. The coordinates of center are (0,0).

So if stepInKernel is equal 1 then all pixels take part in processing.

For example kernel is 5x5.

If stepInKernel == 1 then

the pixels in processing:

(-2,-2) ,(-1,-2), (0,-2),(1,-2),(2,-2),

(-2,-1) ,(-1,-1), (0,-1),(1,-1),(2,-1),

(-2,0) ,(-1,0), (0,0),(1,0),(2,0),

(-2,1) ,(-1,1), (0,1),(1,1),(2,1),

(-2,2) ,(-1,2), (0,2),(1,2),(2,2).

If stepInKernel == 2 then

(-2,-2) , (0,-2),(2,-2),

(-2,0) , (0,0),(2,0),

(-2,2) , (0,2),(2,2).

PS

Such be better:

status = ippiFilterBilateralGetBufSize_8u_C1R(ippiFilterBilateralGauss, imgSize, kernelSize, &buffer);
pSpec = (IppiFilterBilateralSpec*)ippsMalloc_8u(buffer);
status = ippiFilterBilateralInit_8u_C1R(ippiFilterBilateralGauss, kernelSize, 1.0, 1.0, stepInKernel, pSpec);
status = ippiFilterBilateral_8u_C1R(srcGrayImg, srcGrayStep, dstGrayImg,dstGrayStep,imgSize, kernelSize, pSpec);

0 Kudos
malikcoates
Beginner
884 Views
Thank you that is very helpful.

One more question: What is the relationship between kernelSize, and the posSquareSigma?

In the above example we find:
status = ippiFilterBilateralInit_8u_C1R(ippiFilterBilateralGauss, kernelSize, 1.0, 1.0, stepInKernel, pSpec);

I'm thinking that the kernelSize should typically be sqrt(posSquareSigma)*stepInKernel*2+1 and that higher values would have no effect and lower values would be like using a lower posSquareSigma? So, if posSquareSigma and stepInKernel are both 1, then I assume we would want a kernel size of 3x3.

Or is there more going on here?
0 Kudos
nonamme
Beginner
884 Views
please show me an example of using this function and ranges of parameters (kernelstep, kernelsize, valsquaresigma, possquaresigma). function returns noerror but the result is an exact copy of input data.
I use functions like this:

IppiSize ippiImgSize;
ippiImgSize.height = pFrameIn->GetHeight();
ippiImgSize.width = pFrameIn->GetWidth();

IppiSize ippiKernelSize;
ippiKernelSize.height = nKernelSize;
ippiKernelSize.width = nKernelSize;

int nBufferSize = 0;

IppiFilterBilateralType ippiFilterType = ippiFilterBilateralGauss;
IppStatus ippiStatus;

ippiStatus = ippiFilterBilateralGetBufSize_8u_C1R(ippiFilterType, ippiImgSize, ippiKernelSize, &nBufferSize);

IppiFilterBilateralSpec *pSpec = (IppiFilterBilateralSpec*) ippsMalloc_8u(nBufferSize);

int nStepInKernel = nKernelStep;

ippiStatus = ippiFilterBilateralInit_8u_C1R(ippiFilterType, ippiKernelSize,
fValSquareSigma, fPosSquareSigma, nStepInKernel, pSpec);

Ipp8u *pSrc = (Ipp8u*) FrameGray8SRC.GetPointer();

Ipp8u *pDst = (Ipp8u*) FrameGray8DST.GetPointer();

ippiStatus = ippiFilterBilateral_8u_C1R(pSrc, FrameGray8SRC.GetByteSpan(),
pDst, FrameGray8DST.GetByteSpan(),
ippiImgSize, ippiKernelSize, pSpec);

=====================
Oh, I find the cause of trouble: the Sigma values should be at range 1500 and more ( for 5x5 kernel) . And we should add to out image borders with size equal to kernelsize
0 Kudos
Vladimir_Dudnik
Employee
884 Views

Great, does that solve all your questions?

Vladimir

0 Kudos
Intel_C_Intel
Employee
884 Views

Is there a possibility to get a fully working example of the bilateral filter ?

What is the difference between the ippiFilterBilateralGauss and the ippiFilterBilateralGaussFast ?

What is the buffer size we should get when using image of size (M,N) with filter kernel (k,j) ?

I copied the last example in the thread and get no error - yet the image is invalid as if nothing has happened.

0 Kudos
Vladimir_Dudnik
Employee
884 Views

Hello,

there is example how to call IPP bilateral filter

#include

#include

#include "ippcore.h"

#include "ipps.h"

#include "ippi.h"

#define D_WIDTH 8

#define D_HEIGHT 8

#define D_MAX_W_KNL 5

#define D_MAX_H_

?NL 5

int main( void )

{

Ipp8u *src, *src_start;

Ipp8u *dst1, *dst2, *dst3;

Ipp8u *ptmp;

int width_src, height_src;

int width_dst, height_dst;

int step_src;

int step_dst1, step_dst2, step_dst3;

int bufsize;

int stepInKernel;

IppiSize roi;

IppiSize kernel;

int i, j;

Ipp32f valsigma;

Ipp32f possigma;

IppiFilterBilateralSpec *pSpec;

width_src = D_WIDTH + D_MAX_W_KNL - 1;

height_src = D_HEIGHT + D_MAX_H_?NL - 1;

src = ippiMalloc_8u_C1( width_src, height_src, &step_src );

for ( i = 0, ptmp = src; i < height_src; i++ ) {

for ( j = 0; j < width_src; j++ ) {

ptmp = (Ipp8u)rand();

}

ptmp = (Ipp8u *)( (char *)ptmp + step_src );

}

src_start = (Ipp8u *)( (char *)src + (D_MAX_H_?NL>>1) * step_src );

src_start += (D_MAX_W_KNL>>1);

width_dst = D_WIDTH;

height_dst = D_HEIGHT;

dst1 = ippiMalloc_8u_C1( width_dst, height_dst, &step_dst1 );

dst2 = ippiMalloc_8u_C1( width_dst, height_dst, &step_dst2 );

dst3 = ippiMalloc_8u_C1( width_dst, height_dst, &step_dst3 );

roi.width = D_WIDTH;

roi.height = D_HEIGHT;

kernel.width = D_MAX_W_KNL;

kernel.height = D_MAX_H_?NL;

ippiFilterBilateralGetBufSize_8u_C1R( ippiFilterBilateralGauss, roi, kernel, &bufsize);

pSpec = (IppiFilterBilateralSpec *)ippsMalloc_8u( bufsize );

valsigma = 16.f;

possigma = 16.f;

stepInKernel = 1;

ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, valsigma, possigma,

stepInKernel, pSpec );

ippiFilterBilateral_8u_C1R( src_start, step_src, dst1, step_dst1, roi, kernel, pSpec );

valsigma = 1.f;

possigma = 1.f;

stepInKernel = 1;

ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, valsigma, possigma,

stepInKernel, pSpec );

ippiFilterBilateral_8u_C1R( src_start, step_src, dst2, step_dst2, roi, kernel, pSpec );

valsigma = 16.f;

possigma = 16.f;

stepInKernel = 2;

ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, valsigma, possigma,

stepInKernel, pSpec );

ippiFilterBilateral_8u_C1R( src_start, step_src, dst3, step_dst3, roi, kernel, pSpec );

ippsFree( pSpec );

printf(" Src =");

for ( i = 0, ptmp = src; i < height_src; i++ ) {

printf(" ");

for ( j = 0; j < width_src; j++ ) {

printf("%3d ",ptmp);

}

ptmp = (Ipp8u *)( (char *)ptmp + step_src );

}

printf(" Dst1 =");

for ( i = 0, ptmp = dst1; i < height_dst; i++ ) {

printf(" ");

for ( j = 0; j < width_dst; j++ ) {

printf("%3d ",ptmp);

}

ptmp = (Ipp8u *)( (char *)ptmp + step_dst1 );

}

printf(" Dst2 =");

for ( i = 0, ptmp = dst2; i < height_dst; i++ ) {

printf(" ");

for ( j = 0; j < width_dst; j++ ) {

printf("%3d ",ptmp);

}

ptmp = (Ipp8u *)( (char *)ptmp + step_dst2 );

}

printf(" Dst3 =");

for ( i = 0, ptmp = dst3; i < height_dst; i++ ) {

printf(" ");

for ( j = 0; j < width_dst; j++ ) {

printf("%3d ",ptmp);

}

ptmp = (Ipp8u *)( (char *)ptmp + step_dst3 );

}

ippiFree(dst3);

ippiFree(dst2);

ippiFree(dst1);

ippsFree(src);

return 0;

}

Regards,
Vladimir

0 Kudos
long__bingquan
Beginner
884 Views

Community Admin wrote:

Is there a possibility to get a fully working example of the bilateral filter ?

What is the difference between the ippiFilterBilateralGauss and the ippiFilterBilateralGaussFast ?

What is the buffer size we should get when using image of size (M,N) with filter kernel (k,j) ?

I copied the last example in the thread and get no error - yet the image is invalid as if nothing has happened.

Have u fixed the problem u described in the last line?

0 Kudos
long__bingquan
Beginner
884 Views

Community Admin wrote:

Is there a possibility to get a fully working example of the bilateral filter ?

What is the difference between the ippiFilterBilateralGauss and the ippiFilterBilateralGaussFast ?

What is the buffer size we should get when using image of size (M,N) with filter kernel (k,j) ?

I copied the last example in the thread and get no error - yet the image is invalid as if nothing has happened.

Have you fixed the problem ? I meet the same.

0 Kudos
Reply