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

ippiConvValid and ippiFilter

Adel_El-rayyes
Beginner
392 Views
can somebody explain the difference between ippiConvValid and ippiFilter. I don't see the difference. any help would be great!
0 Kudos
1 Solution
Chao_Y_Intel
Moderator
392 Views

Hi,

Please find some comemnts from our experts:

Let t represents mask (filter) and x image:

ConvFull case calculates the full cyclic convolution of two images as there is a border of size (mask-1) around the image filled with zeroes:

1st point: 2nd point: 3rd point:

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

tttttxxxxxxxxxxxxxx 0tttttxxxxxxxxxxxxxx 00tttttxxxxxxxxxxxxxx

0000xxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxxx

0000xxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxx 00000xxxxxxxxxxxxxxxx

0000xxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxx 00000xxxxxxxxxxxxxxxx etc.

ConvValid case calculates its valid part only without assumption on any border:

1st point: 2nd point: 3rd point:

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx etc.

Filter function works as ConvSame case but uses real pixels outside ROI so user must be sure that (mask/2-1) pixels border is available around the ROI. It is possible to manipulate with pointers to ROI and ROI size in order to have the same result both for Filter and ConvValid, but Filter has several limitations for example for C3/C4/AC4 coefficients for R,G,B and A are the same, while Conv convolve two images so if the second image is interpreted as a filter you can have different coefficients for each channel. Filter is optimized for masks size range 3x3 11x11, while Conv optimized for any image sizes as for ~>11x11 images uses convolution theorem (based on FFT).

Thanks,
Chao

View solution in original post

0 Kudos
3 Replies
Chao_Y_Intel
Moderator
393 Views

Hi,

Please find some comemnts from our experts:

Let t represents mask (filter) and x image:

ConvFull case calculates the full cyclic convolution of two images as there is a border of size (mask-1) around the image filled with zeroes:

1st point: 2nd point: 3rd point:

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

ttttt00000000000000 0ttttt00000000000000 00ttttt00000000000000

tttttxxxxxxxxxxxxxx 0tttttxxxxxxxxxxxxxx 00tttttxxxxxxxxxxxxxx

0000xxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxxx

0000xxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxx 00000xxxxxxxxxxxxxxxx

0000xxxxxxxxxxxxxxx 0000xxxxxxxxxxxxxxxx 00000xxxxxxxxxxxxxxxx etc.

ConvValid case calculates its valid part only without assumption on any border:

1st point: 2nd point: 3rd point:

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

tttttxxxxxxxxxxxxxx xtttttxxxxxxxxxxxxx xxtttttxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx etc.

Filter function works as ConvSame case but uses real pixels outside ROI so user must be sure that (mask/2-1) pixels border is available around the ROI. It is possible to manipulate with pointers to ROI and ROI size in order to have the same result both for Filter and ConvValid, but Filter has several limitations for example for C3/C4/AC4 coefficients for R,G,B and A are the same, while Conv convolve two images so if the second image is interpreted as a filter you can have different coefficients for each channel. Filter is optimized for masks size range 3x3 11x11, while Conv optimized for any image sizes as for ~>11x11 images uses convolution theorem (based on FFT).

Thanks,
Chao

0 Kudos
Ying_H_Intel
Employee
392 Views

Hi

I guess you mean thecaculating formula of ippiConvValid and ippiFilter. Yes, they are almost same.

Just a little difference in function form and parameter according to the purpose of function,
likeand ippiFilter, the src 1 is image with 8u 3channel, but the Kernalis 32s, 1 channel.
ippiconvValid, the src 1 and src 2 are same data type image, for example 8u, 3 channel.
so when your image is 1 channel thethey are same, but not when multiple channel.
In general,when operate convolutionon two image, the ippiconvValid is needed.
and if operate with afilter, the ippiFilter is better.

Regards,
Ying

By helpingremember , attach the test code
void main()
{
Ipp16s src1[4*4]={ 0, 1, 2, 3,
0, 1, 2, 3,
1, 2, 3, 0,
2, 3, 1, 0};
Ipp16s src2[3*1]={1, -2, -1};

Ipp16s dst1[6*6]={0};
Ipp16s dst2[2*4]={0};
Ipp16s dst3[2*4]={0};

IppiSize src1Size = { 4, 4 };
IppiSize src2Size = { 3, 1 };
int divisor = 1;
int sign = 1;
int i=0, j=0;
IppStatus s ;

s= ippiConvFull_16s_C1R ( src1, 4*sizeof(Ipp16s), src1Size, src2,3*sizeof(Ipp16s), src2Size, dst1, 6*sizeof(Ipp16s), divisor);

s=ippiConvValid_16s_C1R ( src1, 4*sizeof(Ipp16s), src1Size, src2,3*sizeof(Ipp16s), src2Size, dst2, 2*sizeof(Ipp16s), divisor );

Ipp32s kern[] = { 1, -2, -1 }; // using "Sobel" kernel.
IppiSize kernelSize = {3,1};
IppiPoint anchor = {2,0}; // the anchor need be bottom-right.
IppiSize dstRoiSize={2,4};

s=ippiFilter_16s_C1R(src1, 4*sizeof(Ipp16s),dst3, 2*sizeof(Ipp16s), dstRoiSize, kern,kernelSize, anchor, divisor);

printf ("ippiFilter_16s dst3, %s\n", ippGetStatusString(s));
return ;
}

The result
src1
0 1 2 3
0 1 2 3
1 2 3 0
2 3 1 0
src2
1 -2 -1 // when calculate, the element is in inverse order.
ConvFul dst1
0 1 0 -2 -8 -3
0 1 0 -2 -8 -3
1 0 -2 -8 -3 0
2 -1 -7 -5 -1 0
0 0 0 0 0 0
0 0 0 0 0 0
ippiConvValid dst2
0 -2
0 -2
-2 -8
-7 -5
ippiFilter_16s dst3, ippStsNoErr: No error, it's OK
0 -2
0 -2
-2 -8
-7 -5
Press any key to continue . . .

0 Kudos
Adel_El-rayyes
Beginner
392 Views
Hi Chao,

sounds complicated, but i think i got it, thank you!
0 Kudos
Reply