Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Lamp
Beginner
82 Views

How to create the mask for ippiDilate?

Jump to solution
Hi,

Is there any samples to create the mask for ippiDilate?

If I use the API ippiDilate3x3, the result is the same as the sample shows,
but when try to dilate it with ippiDilate, the result is the same as input matrix without any change.

the code:

[cpp]          	IppiSize roi = {5,5};
Ipp8u kernel[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; IppiSize kernelSize = {4,4}; IppiPoint anchor = { 1, 1 }; ippiDilate_8u_C1IR(x, 7, roi, kernel, kernelSize, anchor);[/cpp]

X is a 7 * 7 matrix.

Example 8-1. Dilation of a Dot

IppStatus dilate( void ) {

Ipp8u x[7*5];

IppiSize roi = {7,5};

ippiSet_8u_C1R( 0, x, 7, roi );

x[2*7+3] = 1;

roi.width = roi.width - 2;

roi.height = roi.height - 2;

return ippiDilate3x3_8u_C1IR( x+7+1, 7, roi );

}

The destination image x contains:

00 00 00 00 00 00 00

00 00 01 01 01 00 00

00 00 01 01 01 00 00

00 00 01 01 01 00 00


Regards,
Xie

0 Kudos

Accepted Solutions
Ying_H_Intel
Employee
82 Views
Hi Xie,

ippiDilate3x3_8u_C1IRuse a symmetric 3x3 mask

If you use

Ipp8ukernel[]={1,1,1,1,1,1,1,1,1}; //1,1,1,1,1,1,1};
  • IppiSizekernelSize={3,3};
  • IppiPointanchor={1,1};
  • ippiDilate_8u_C1IR(x+7+1,7,roi,kernel,kernelSize,anchor);

    You will get the same result as ippiDilate3x3_8u_C1IR.

    If use IppiSizeroi={5,5} and kernelSize={4,4},anchor={1,1};you may need to consider to extend original image with the border( for example, add width=1, heigh=1,border at up and left of image, bottom +3 row) as the dicussion in http://software.intel.com/en-us/articles/intel-integrated-performance-primitives-intel-ipp-processin...
    or use the function ippiDilateBorderReplicate, which consider the image border within function.

    a example code:

    #include
    #include
    #include
    #include

    int main()
    {
    ippStaticInit();

    // Print the version of ipp being used
    const IppLibraryVersion* lib = ippcvGetLibVersion();
    printf("%s %s %d.%d.%d.%d\n", lib->Name, lib->Version,lib->major, lib->minor, lib->majorBuild, lib->build);

    IppStatus status;
    Ipp8u x[7*5];
    IppiSize roi = {7,5};

    ippiSet_8u_C1R( 0, x, 7, roi );
    x[2*7+3] = 1;

    printf ("x\n");
    for(int i=0; i<5;i++)
    {
    for(int j=0; j<7;j++)
    printf (" %3d", x[i*7+j]);
    printf ("\n");
    }

    Ipp8u y[7*5];
    ippiSet_8u_C1R( 0, y, 7, roi );

    roi.width = 5;
    roi.height = 5;

    IppiMorphState* ppState;
    Ipp8u kernel[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
    IppiSize kernelSize = {4,4};
    IppiPoint anchor = { 1, 1 };

    status=ippiMorphologyInitAlloc_8u_C1R( roi.width, kernel, kernelSize, anchor,
    &ppState);
    printf("%s\n", ippGetStatusString(status));
    status=ippiDilateBorderReplicate_8u_C1R( x, 7, y, 7, roi,
    ippBorderRepl, ppState);
    printf("%s\n", ippGetStatusString(status));
    ippiMorphologyFree(ppState);

    printf ("ippiDilateBorderReplicate_8u_C1R\n");
    for(int i=0; i<5;i++)
    {
    for(int j=0; j<7;j++)
    printf (" %3d", y[i*7+j]);
    printf ("\n");
    }

    return 0;
    }


    Hope it helps,
    Best Regards,
    Ying

    View solution in original post

    1 Reply
    Ying_H_Intel
    Employee
    83 Views
    Hi Xie,

    ippiDilate3x3_8u_C1IRuse a symmetric 3x3 mask

    If you use

    Ipp8ukernel[]={1,1,1,1,1,1,1,1,1}; //1,1,1,1,1,1,1};
  • IppiSizekernelSize={3,3};
  • IppiPointanchor={1,1};
  • ippiDilate_8u_C1IR(x+7+1,7,roi,kernel,kernelSize,anchor);

    You will get the same result as ippiDilate3x3_8u_C1IR.

    If use IppiSizeroi={5,5} and kernelSize={4,4},anchor={1,1};you may need to consider to extend original image with the border( for example, add width=1, heigh=1,border at up and left of image, bottom +3 row) as the dicussion in http://software.intel.com/en-us/articles/intel-integrated-performance-primitives-intel-ipp-processin...
    or use the function ippiDilateBorderReplicate, which consider the image border within function.

    a example code:

    #include
    #include
    #include
    #include

    int main()
    {
    ippStaticInit();

    // Print the version of ipp being used
    const IppLibraryVersion* lib = ippcvGetLibVersion();
    printf("%s %s %d.%d.%d.%d\n", lib->Name, lib->Version,lib->major, lib->minor, lib->majorBuild, lib->build);

    IppStatus status;
    Ipp8u x[7*5];
    IppiSize roi = {7,5};

    ippiSet_8u_C1R( 0, x, 7, roi );
    x[2*7+3] = 1;

    printf ("x\n");
    for(int i=0; i<5;i++)
    {
    for(int j=0; j<7;j++)
    printf (" %3d", x[i*7+j]);
    printf ("\n");
    }

    Ipp8u y[7*5];
    ippiSet_8u_C1R( 0, y, 7, roi );

    roi.width = 5;
    roi.height = 5;

    IppiMorphState* ppState;
    Ipp8u kernel[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
    IppiSize kernelSize = {4,4};
    IppiPoint anchor = { 1, 1 };

    status=ippiMorphologyInitAlloc_8u_C1R( roi.width, kernel, kernelSize, anchor,
    &ppState);
    printf("%s\n", ippGetStatusString(status));
    status=ippiDilateBorderReplicate_8u_C1R( x, 7, y, 7, roi,
    ippBorderRepl, ppState);
    printf("%s\n", ippGetStatusString(status));
    ippiMorphologyFree(ppState);

    printf ("ippiDilateBorderReplicate_8u_C1R\n");
    for(int i=0; i<5;i++)
    {
    for(int j=0; j<7;j++)
    printf (" %3d", y[i*7+j]);
    printf ("\n");
    }

    return 0;
    }


    Hope it helps,
    Best Regards,
    Ying

    View solution in original post