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

Problems encountered when using ippMorphOpenBorder

XDu
Beginner
1,435 Views

Hi, I'm having some problems with ippiMorphOpenBorder_8u_C1R.

#include <stdio.h>
#include<Windows.h>
#include "ipp.h"


int main(){
IppiSize roiSize = {16, 5 };
IppiSize maskSize = { 4, 4 };
int iSpecSize, iBufferSize;

ippiMorphAdvGetSize_8u_C1R(roiSize, maskSize, &iSpecSize, &iBufferSize);

IppiMorphAdvState *pSpec = (IppiMorphAdvState*)ippsMalloc_8u(iSpecSize);
Ipp8u *pBuffer = ippsMalloc_8u(iBufferSize);

Ipp8u pMask[4*4] = { 1,0,0,1,0,1,1,0,1,1,1,0,0,1,1,1};

ippiMorphAdvInit_8u_C1R(roiSize, pMask, maskSize, pSpec, pBuffer);

Ipp8u pSrc[80] = { 10, 126, 83, 244, 162, 22, 183, 137, 224, 163, 114, 112, 42, 13, 160, 225,
39, 106, 206, 197, 105, 21, 189, 110, 79, 0, 99, 134, 41, 75, 51, 69,
158, 21, 158, 231, 75, 146, 218, 94, 173, 93, 226, 68, 65, 16, 190, 19,
233, 19, 4, 152, 146, 177, 159, 165, 20, 113, 207, 7, 89, 163, 113, 183,
194, 57, 129, 85, 198, 216, 221, 209, 221, 47, 75, 108, 156, 136, 190, 223
};
Ipp8u pDst[80] = { 0 };
IppStatus sts = ippiMorphOpenBorder_8u_C1R(pSrc, 16, pDst, 16, roiSize, ippBorderRepl, 0, pSpec, pBuffer);

for (int i = 0; i < 5; i++){
for (int j = 0; j < 16; j++){
printf("%d ", pDst[i * 16 + j]);
}
printf("\n");
}
printf("\n");
printf("\n");
printf("%d",sts);
system("pause");

}

Based on the results of my previous use of ErodeBorder_8u_C1R and DilateBorder_8u_C1R, I think when the mask is 4x4, it will fill 5x5. But the result of MorphOpenBorder_8u_C1R was different from what I thought.

Actual results:

10 75 75 75 75 22 79 79 79 79 13 16 16 13 19 19
19 75 75 75 105 22 79 105 79 79 20 20 16 19 19 19
19 19 85 85 75 146 105 105 146 79 20 68 19 16 68 19
57 19 19 85 146 105 146 146 146 47 75 47 89 136 113 113
57 57 85 85 146 146 146 146 47 47 75 75 89 136 136 136

I think:

10 75 75 75 75 22 79 79 79 79 13 16 16 13 19 19
19 75 75 75 105 22 79 105 79 79 20 20 16 19 19 19
19 19 85 85 75 146 105 79 146 79 20 68 19 16 68 19
57 19 4 85 146 105 146 146 20 47 75 7 89 136 113 113
57 57 85 85 146 146 146 146 47 47 75 75 89 136 136 136

So I'm confused if the mask is 4x4 and what the correct result should be and how it should be handled.

Thank you.

0 Kudos
6 Replies
NoorjahanSk_Intel
Moderator
1,406 Views

Hi,

Thanks for reaching out to us.

The issue is reproducible from our end also. We are looking into this issue internally. We will get back to you soon.

 

Thanks & Regards

Noorjahan.

 

0 Kudos
XDu
Beginner
1,372 Views

Hi,
Thank you for your reply and look forward to your survey results.

My English is average,if there is any impoliteness, please don't mind.


Thanks & Regards.
boyang

0 Kudos
Ruqiu_C_Intel
Moderator
1,284 Views

Hello,

Thanks for your attention.

There is an issue in advanced morphology (Open, Close, etc.) for even-sized kernels. We have already fixed it.

Please use odd-size kennel for your case. For your sample, we re-write it as below, it works well now. And it demonstrates that ippiMorphOpenBorder_8u_C1R has same results as ErodeBorder_8u_C1R + DilateBorder_8u_C1R


#include <stdio.h>

#include "ipp.h"


int open() {

  IppiSize roiSize = { 16, 5 };

  IppiSize maskSize = { 5, 5 };

  int iSpecSize, iBufferSize;


  ippiMorphAdvGetSize_8u_C1R(roiSize, maskSize, &iSpecSize, &iBufferSize);


  IppiMorphAdvState* pSpec = (IppiMorphAdvState*)ippsMalloc_8u(iSpecSize);

  Ipp8u* pBuffer = ippsMalloc_8u(iBufferSize);


  Ipp8u pMask[5 * 5] = { 0,0,0,0,0,

              0,1,0,0,1,

              0,0,1,1,0,

              0,1,1,1,0,

              0,0,1,1,1 };


  ippiMorphAdvInit_8u_C1R(roiSize, pMask, maskSize, pSpec, pBuffer);


  Ipp8u pSrc[80] = { 10, 126, 83, 244, 162, 22, 183, 137, 224, 163, 114, 112, 42, 13, 160, 225,

  39, 106, 206, 197, 105, 21, 189, 110, 79, 0, 99, 134, 41, 75, 51, 69,

  158, 21, 158, 231, 75, 146, 218, 94, 173, 93, 226, 68, 65, 16, 190, 19,

  233, 19, 4, 152, 146, 177, 159, 165, 20, 113, 207, 7, 89, 163, 113, 183,

  194, 57, 129, 85, 198, 216, 221, 209, 221, 47, 75, 108, 156, 136, 190, 223

  };

  Ipp8u pDst[80] = { 0 };

  IppStatus sts = ippiMorphOpenBorder_8u_C1R(pSrc, 16, pDst, 16, roiSize, ippBorderRepl, 0, pSpec, pBuffer);


  for (int i = 0; i < 5; i++) {

    for (int j = 0; j < 16; j++) {

      printf("%4d ", pDst[i * 16 + j]);

    }

    printf("\n");

  }

  printf("\n");

  printf("\n");

  printf("%d", sts);

  return 0;

}


int main() {

  IppiSize roiSize = { 16, 5 };

  IppiSize maskSize = { 5, 5 };

  int iSpecSize = 0, iBufferSize = 0;




  ippiMorphologyBorderGetSize_8u_C1R(roiSize, maskSize, &iSpecSize, &iBufferSize);

  IppiMorphState* pSpec = (IppiMorphState*)ippsMalloc_8u(iSpecSize);



  Ipp8u* pBuffer = ippsMalloc_8u(iBufferSize);


  Ipp8u pMaskE[5 * 5] = { 0,0,0,0,0,

              0,1,0,0,1,

              0,0,1,1,0,

              0,1,1,1,0,

              0,0,1,1,1 };


  Ipp8u pMaskD[5 * 5] = { 1,1,1,0,0,

              0,1,1,1,0,

              0,1,1,0,0,

              1,0,0,1,0,

              0,0,0,0,0 };



  Ipp8u pSrc[80] = { 10, 126, 83, 244, 162, 22, 183, 137, 224, 163, 114, 112, 42, 13, 160, 225,

  39, 106, 206, 197, 105, 21, 189, 110, 79, 0, 99, 134, 41, 75, 51, 69,

  158, 21, 158, 231, 75, 146, 218, 94, 173, 93, 226, 68, 65, 16, 190, 19,

  233, 19, 4, 152, 146, 177, 159, 165, 20, 113, 207, 7, 89, 163, 113, 183,

  194, 57, 129, 85, 198, 216, 221, 209, 221, 47, 75, 108, 156, 136, 190, 223

  };

  Ipp8u pDst[80] = { 0 };


  ippiMorphologyBorderInit_8u_C1R(roiSize, pMaskE, maskSize, pSpec, pBuffer);


  IppStatus sts = ippiErodeBorder_8u_C1R(pSrc, 16, pDst, 16, roiSize, ippBorderRepl, 0, pSpec, pBuffer);


  for (int i = 0; i < 5; i++) {

    for (int j = 0; j < 16; j++) {

      printf("%4d ", pDst[i * 16 + j]);

    }

    printf("\n");

  }

  printf("\n");

  printf("\n");



  Ipp8u pDst2[80] = { 0 };


  ippiMorphologyBorderInit_8u_C1R(roiSize, pMaskD, maskSize, pSpec, pBuffer);

  sts = ippiDilateBorder_8u_C1R(pDst, 16, pDst2, 16, roiSize, ippBorderRepl, 0, pSpec, pBuffer);



  for (int i = 0; i < 5; i++) {

    for (int j = 0; j < 16; j++) {

      printf("%4d ", pDst2[i * 16 + j]);

    }

    printf("\n");

  }

  printf("\n");

  printf("\n");

  printf("%d", sts);


  printf("calling advanced morph\n\n\n");

  open();


}



0 Kudos
XDu
Beginner
1,236 Views

Hi,

Thank you for your reply. I'm sorry I just saw it today. Then may I ask whether the revised version has been released? Can I download it?

0 Kudos
Ruqiu_C_Intel
Moderator
1,221 Views

It will be available in IPP update 2021.4, which is the next release version


0 Kudos
Ruqiu_C_Intel
Moderator
1,142 Views

This issue is closing and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only. 


0 Kudos
Reply