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

Why ippiFilter should be deprecated?

Dongkyu
Beginner
1,040 Views

 Hello,

 I'm a ten-year user of the IPP.
 I've been using ippiFilter in many parts of my codes. And I found that the function is deprecated.

 The manual recommends that I should use ippiFilterBorder instead.
 But I wonder why ippiFilter is obsolete.

 I think that ippiFilterBorder has the function of ippiFilter with some border options.
 But there are many cases that border options don't be needed or a user may want to copy borders by oneself.
 So, I think that ippiFilter is still needed in these cases and should not be replaced with ippiFilterBorder.
 ippiFilter is very important base function in the image processing as you know.

 Do I use ippiFilterBorder even when I don't need arguments like border, borderValue, pSpec and pBuffer?
 Should I copy borders even if I filter a small inner ROI which don't need to extend borders?
 I don't want to add allocate and initialize functions like ippiFilterBorderGetSize, ippsMalloc and ippiFilterBorderInit, either.
 It doesn't have any benefit even for speed issue.

 I hope that ippiFilter is not deprecated even for backward compatibility.
 ippiFilterRow and ippiFilterColumn functions are not deprecated, either.

 Thank & regards,

 Dongkyu

0 Kudos
9 Replies
Igor_A_Intel
Employee
1,040 Views

Hi Dongkyu,

All API changes in IPP have been done in order to make application level threading of pipelines of IPP functions more effective, to remove internal memory allocations and make filtering operation "non reducing" (it's known that CopyReplicate/<...>Border functionality significantly affects performance), to make possible processing of huge images (by slices), etc. ippiFilter had implicit malloc(). For FilterBorder you should do it explicitly - therefore you can reuse this memory buffer for other needs and make this buffer "warm". Just set IppiBorderType border to ippBorderInMem and you'll have the same function behavior as ippiFilter_xx has.

regards, Igor

0 Kudos
Dongkyu
Beginner
1,040 Views

  Igor, thanks for reply.

 But I don't know exactly how I can reuse this memory buffer for other needs and make this buffer "warm" as you said.

 For example, I'm trying to filter an image repeatedly with 8 directional and 5 varying kernel sizes.(3x3, 5x5, 9x9, 13x13, 17x17)
 Please teach me how to make the max speed using FilterBorder.

 I've tried to compare FilterBorder and Filter.
 Sample image is 256x256 size and 16-bit.

 Case1: using FilterBorder

    IppiSize kernelSizeMax = { 17,17 };
   int specSize, bufferSize;
   IppiFilterBorderSpec* pSpec;
   Ipp8u* pBuffer;
   IppStatus status;
   Ipp32f   borderValue = 0;

   status = ippiFilterBorderGetSize(kernelSizeMax, roiSize, ipp32f, ipp32f, 1, &specSize, &bufferSize));
   pSpec = (IppiFilterBorderSpec*)ippsMalloc_8u(specSize);
   pBuffer = ippsMalloc_8u(bufferSize);

   for (int d = 0; d < 8; ++d)
   {
      for (int n = 0; n < 5; ++n)
      {
         status = ippiFilterBorderInit_32f(kernel, kernelSize, ipp32f, 1, ippRndZero, pSpec);
         status = ippiFilterBorder_32f_C1R(src, srcStep, dst, dstStep, roiSize, ippBorderConst, &borderValue, pSpec, pBuffer);
      }
   }

   ippsFree(pSpec);
   ippsFree(pBuffer);
 

   Case2: using Filter
 
   IppiSize kernelSizeMax = { 17,17 };
   int hkernelMax = 9;

   IppStatus status;

   status = ippiCopyConstBorder_32f_C1R(src, srcStep, srcRoi, srcExt, srcExtStep, srcExtRoi, hkernelMax, hkernelMax, 0);

   for (int d = 0; d < 8; ++d)
   {
      for (int n = 0; n < 5; ++n)
      {
           IppiPoint   anchor = { kernelSize/2, kernelSize/2 };
           status = ippiFilter_32f_C1R(srcRoiLTPtr, srcExtStepdst, dstStep, roiSize, kernel, kernelSize, anchor);
      }
   }

  
  Result:
   Case 2: using Filter was about 30% faster than Case 1: using FilterBorder.
   How can I speed up in Case 1 like Case 2?
 
   One more thing, FilterBorder does not have anchor parameter. I need it. My directional kernels don't have the center anchor point.
   How can I set the anchor point?
 
   Thanks & regards,
   Dongkyu.
 
0 Kudos
Igor_A_Intel
Employee
1,040 Views

Hi Dongkyu,

You provided very synthetic case with 2 unequal approaches. Border processing is too expensive operation. If you compare performance of one call to CopyConstBorder+Filter and one call to FilterBorder(...ippBorderConst...) - you'll see that the second call is visibly faster. In your case, when the same const border is used in a filtering loop - you should create border only once (as for "old" Filter function) and use ippBorderInMem mode. The Anchor parameter is responsible for pSrc shift only - therefore you always can simulate it by pSrc parameter shifting:

ippiFilter internals for applying Anchor parameter:     strtSrc = (Ipp8u*)pSrc - ( kHeight - anchor.y - 1 ) * srcStep - ( kWidth - anchor.x - 1 );

regards, Igor.
 

0 Kudos
Dongkyu
Beginner
1,040 Views

 Hi, Igor.

 Thanks for reply.

 I understood for the speed issue. I'm gonna use copyBorder and ippBorderInMem option.

 But for the anchor parameter I don't know exactly what you said.

 I've done a simple test by source shift as you said, but I didn't understand.
 But I couldn't simulate it by pSrc parameter shifting.

 Show me a real example for simulating anchor which is not the center of a kernel, please.

 Thanks & regards.

 Dongkyu.

0 Kudos
Igor_A_Intel
Employee
1,040 Views

Hello,

b = border value (if const than all b[X,X] values are equal, if replicate – than b[X,Y]==x[X,Y])

x[X,Y] = ROI, roiSize = {N,M}

 

b00 b00 b00 b01 b02 b03 b04 b05 b06 b07 … b0N

b00 b00 b00 b01 b02 b03 b04 b05 b06 b07 … b0N

b00 b00 x00 x01 x02 x03 x04 x05 x06 x07 … x0N

b10 b10 x10 x11 x12 x13 x14 x15 x16 x17 … x1N

b20 b20 x20 x21 x22 x23 x24 x25 x26 x27 … x2N

b30 b30 x30 x31 x32 x33 x34 x35 x36 x37 … x3N

b40 b40 x40 x41 x42 x43 x44 x45 x46 x47 … x4N

b50 b50 x50 x51 x52 x53 x54 x55 x56 x57 … x5N

…………………………………………………………………………………………………………………….

bM0 bM0 xM0 xM1 xM2 xM3 xM4 xM5 xM6 xM7 … xMN

 

k[X,Y] = kernel, size = {5,5}

 

k00 k01 k02 k03 k04

k10 k11 k12 k13 k14

k20 k21 k22 k23 k24

k30 k31 k32 k33 k34

k40 k41 k42 k43 k44

 

if anchor = {2,2} than pSrc should point to x00:

 

k00 k01 k02 k03 k04 b03 b04 b05 b06 b07 … b0N

k10 k11 k12 k13 k14 b03 b04 b05 b06 b07 … b0N

k20 k21 k22 k23 k24 x03 x04 x05 x06 x07 … x0N

k30 k31 k32 k33 k34 x13 x14 x15 x16 x17 … x1N

k40 k41 k42 k43 k44 x23 x24 x25 x26 x27 … x2N

b30 b30 x30 x31 x32 x33 x34 x35 x36 x37 … x3N

b40 b40 x40 x41 x42 x43 x44 x45 x46 x47 … x4N

b50 b50 x50 x51 x52 x53 x54 x55 x56 x57 … x5N

 

if anchor = {1,1} than pSrc should point to x{1,1}: (a point where k[2,2] is applied)

 

b00 b00 b00 b01 b02 b03 b04 b05 b06 b07 … b0N

b00 k00 k01 k02 k03 k04 b04 b05 b06 b07 … b0N

b00 k10 k11 k12 k13 k14 x04 x05 x06 x07 … x0N

b10 k20 k21 k22 k23 k24 x14 x15 x16 x17 … x1N

b20 k30 k31 k32 k33 k34 x24 x25 x26 x27 … x2N

b30 k40 k41 k42 k43 k44 x34 x35 x36 x37 … x3N

b40 b40 x40 x41 x42 x43 x44 x45 x46 x47 … x4N

b50 b50 x50 x51 x52 x53 x54 x55 x56 x57 … x5N

…………………………………………………………………………………………………………………….

bM0 bM0 xM0 xM1 xM2 xM3 xM4 xM5 xM6 xM7 … xMN

 

if anchor = {3,3} than pSrc should point to b00 = x{-1,-1}: (also to the point where k[2,2] is applied), and it’s visible that you should provide additional border row and column at the top and at the left for this case (and at the bottom and right – for the previous)

 

k00 k01 k02 k03 k04

k10 k11 k12 k13 k14 b02 b03 b04 b05 b06 b07 … b0N

k20 k21 k22 k23 k24 b02 b03 b04 b05 b06 b07 … b0N

k30 k31 k32 k33 k34 x02 x03 x04 x05 x06 x07 … x0N

k40 k41 k42 k43 k44 x12 x13 x14 x15 x16 x17 … x1N

    b20 b20 x20 x21 x22 x23 x24 x25 x26 x27 … x2N

    b30 b30 x30 x31 x32 x33 x34 x35 x36 x37 … x3N

    b40 b40 x40 x41 x42 x43 x44 x45 x46 x47 … x4N

    b50 b50 x50 x51 x52 x53 x54 x55 x56 x57 … x5N

    …………………………………………………………………………………………………………………….

    bM0 bM0 xM0 xM1 xM2 xM3 xM4 xM5 xM6 xM7 … xMN

 

Note: ippiFilter transposes a kernel before the filtering operation and therefore anchor coordinates have meaning for initial – non-transposed kernel, while ippiFilterBorder doesn’t transpose a kernel (see the manual).

regards, Igor

 

0 Kudos
Dongkyu
Beginner
1,040 Views

 Hi, Igor.

 I think that your description is different from what I know.

 I agree with you if anchor = {2,2}.
 But if anchor point is not the center of a kernel, I think that it's different from the formula which is described about ippiFilter in the manual.

 

 In your example,

 If anchor = {1,1} then P=3, Q=3 and pSrc should point to x{-1,-1}: (a point where k[1,1] is applied)

 

k44 k43 k42 k41 k40

k34 k33 k32 k31 k30 b02 b03 b04 b05 b06 b07 … b0N

k24 k23 k22 k21 k20 b02 b03 b04 b05 b06 b07 … b0N

k14 k13 k12 k11 k10 x02 x03 x04 x05 x06 x07 … x0N

k04 k03 k02 k01 k00 x12 x13 x14 x15 x16 x17 … x1N

    b20 b20 x20 x21 x22 x23 x24 x25 x26 x27 … x2N

    b30 b30 x30 x31 x32 x33 x34 x35 x36 x37 … x3N

    b40 b40 x40 x41 x42 x43 x44 x45 x46 x47 … x4N

    b50 b50 x50 x51 x52 x53 x54 x55 x56 x57 … x5N

    …………………………………………………………………………………………………………………….

    bM0 bM0 xM0 xM1 xM2 xM3 xM4 xM5 xM6 xM7 … xMN

 

 If anchor = {3,3} than P=1,Q=1 and pSrc should point to x{1,1}: (a point where k[3,3] is applied)

 

b00 b00 b00 b01 b02 b03 b04 b05 b06 b07 … b0N

b00 k44 k43 k42 k41 k40 b04 b05 b06 b07 … b0N

b00 k34 k33 k32 k31 k30 x04 x05 x06 x07 … x0N

b10 k24 k23 k22 k21 k20 x14 x15 x16 x17 … x1N

b20 k14 k13 k12 k11 k10 x24 x25 x26 x27 … x2N

b30 k04 k03 k02 k01 k00 x34 x35 x36 x37 … x3N

b40 b40 x40 x41 x42 x43 x44 x45 x46 x47 … x4N

b50 b50 x50 x51 x52 x53 x54 x55 x56 x57 … x5N

…………………………………………………………………………………………………………………….

bM0 bM0 xM0 xM1 xM2 xM3 xM4 xM5 xM6 xM7 … xMN

 

 Because I use the formula of ippiFilter, kernel coefficients are used in inverse order, I think.

 But the point that I want to say is that the destination point is the anchor point of a kernel, not always the center of the kernel.
 I think that it has different result with that is applied to k22.

 So, I think the anchor parameter is still needed to FilterBorder function if Filter function is deprecated. 
 What do you think about that?

 Regards,

 Dongkyu.

0 Kudos
Igor_A_Intel
Employee
1,040 Views

Dongkyu,

take a look at the "note" from my previous post:

"Note: ippiFilter transposes a kernel before the filtering operation and therefore anchor coordinates have meaning for initial – non-transposed kernel, while ippiFilterBorder doesn’t transpose a kernel (see the manual)."

regards, Igor

 

0 Kudos
Igor_A_Intel
Employee
1,040 Views

filter.jpg

0 Kudos
Dongkyu
Beginner
1,040 Views

 Hi, Igor

 I understood by the last picture. I see that pSrc shift you said means the ROI position shift of the src image due to fix the anchor point to the center of a kernel.
 I tried to test it with some sample codes and it worked well. Thank you.

 I didn't find out any description about the anchor in FilterBorder page of the ippi manual.
 I think that it will be better if the picture and some description about the anchor are added to the manual.
 Anyway, thanks again!

 I think that ippiFilter may be replaced with ippiFilterBorder, now.

 Regards, Dongkyu.

0 Kudos
Reply