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

## Problem with ippiDilate_16u_C1IR

Beginner
411 Views

I am not getting the result that I think I should from ippiDilate_16u_C1IR with some larger kernel sizes. The following is some code which demonstrates the issue. It creates a circular dilation mask of a given radius and applies it to an isolated pixel in the image. I would expect this to result in a reproduction of the mask. (I think there is a 180 degree rotation, but this is unobservable with a circular mask.) This holds true for mask radii up to 7 but fails for 8 and above. The radius 7 mask is 15x15 and the radius 8 mask is 17x17 so the mask size crosses 256 elements between these two radii. The ippiErode_16u_C1IR does not appear to exhibit this problem.

#include

#include "ippdefs.h"

#include "ippi.h"

// Create a disk (circular) structuring element

std::vector createDisk(const size_t radius)

{

size_t nKernel = 2 * radius + 1;

std::vector disk(nKernel * nKernel, 0);

int rSquared = (int)(radius * radius);

for (size_t iRow = 0; iRow < nKernel; ++iRow)

{

int dR = (int)radius - (int)iRow;

for (size_t iCol = 0; iCol < nKernel; ++iCol)

{

int dC = (int)radius - (int)iCol;

if (dR * dR + dC * dC <= rSquared)

disk[iRow * nKernel + iCol] = 1;

}

}

return disk;

}

// Verify that the dilation of a single point centered in an image

// of the appropriate size matches the mask.

bool testDilate(size_t radius)

{

// Construct a circular mask of the specified size.

size_t maskSize = 2 * radius + 1;

std::vector mask = createDisk(radius);

// Create an Ipp image to perform the dilation in.

size_t paddedImageSize = maskSize + 2 * radius;

int stepBytes = 0;

Ipp16u* data = ippiMalloc_16u_C1((int)paddedImageSize, (int)paddedImageSize, &stepBytes);

size_t stepElements = (size_t)stepBytes / sizeof(Ipp16u);

// Set the ROI to the entire image and then set the image to 0.

IppiSize roiSize = {(int)paddedImageSize, (int)paddedImageSize};

Ipp16u* roiStart = data;

ippiSet_16u_C1R(0, roiStart, stepBytes, roiSize);

// Set the roi to a centered square of the same size as the mask.

roiStart = data + radius * stepElements + radius;

roiSize.width = (int)maskSize;

roiSize.height = (int)maskSize;

// Set the center pixel of the image to 1.

roiStart[radius * stepElements + radius] = 1;

// Dilate the image using the mask.

IppiSize ippiMaskSize = {(int)maskSize, (int)maskSize};

IppiPoint anchor = {(int)radius, (int)radius};

ippiDilate_16u_C1IR(roiStart, stepBytes, roiSize, &mask[0], ippiMaskSize, anchor);

// Check that each pixel in the roi matches the mask.

bool good = true;

for (size_t iRow = 0; iRow < maskSize; ++iRow)

{

for (size_t iCol = 0; iCol < maskSize; ++iCol)

{

if (mask[iRow * maskSize + iCol] != roiStart[iRow * stepElements + iCol])

{

good = false;

}

}

}

// Cleanup

if (data != 0)

{

ippiFree(data);

data = 0;

roiStart = 0;

}

return good;

}

3 Replies
Employee
411 Views
Hello,
could you please specify what IPP version and what platform do you use?
Regards,
Vladimir

Beginner
411 Views
Quoting - vdudnik
Hello,
could you please specify what IPP version and what platform do you use?
Regards,
Vladimir

We are using IPP version 5.3.85 on Windows XP SP2

Employee
411 Views
Thanks, we've successfully run your test against IPP 6.0 on Intel Core2 processor. Please note that there were several updates for IPP 5.3, the latest one was update 4, where this issue might be resolved.
Regards,
Vladimir