FilterBorder
Applies a mean filter to the source image and stores the result to the destination image. This function processes three-dimensional images, or volumes. The border pixel values are determined based on the specified border type and border value parameters.
The filter kernel used by this function is initialized by HMPPI_CreateKernel3D_32f. The pSpec space size required by this function needs to be calculated using HMPPI_FilterBorderGetSize, with subsequent initialization—including the incorporation of the created filter kernel—conducted within HMPPI_FilterBorderInit_32f.
The function interface is declared as follows:
- Auxiliary functions:
HmppResult HMPPI_CreateKernel3D_32f(float* kernel, HmpprVolume kernelSize);
HmppResult HMPPI_FilterBorderGetSize(HmpprVolume kernelVolume, HmpprVolume dstRoiVolume, int numChannels, int* pSpecSize);
HmppResult HMPPI_FilterBorderInit_32f(const float* pKernel, HmpprVolume kernelVolume, int numChannels, HmpprFilterBorderSpec* pSpec);
- Main function:
HmppResult HMPPI_FilterBorder_32f_C1V(const float* pSrc, int srcPlaneStep, int srcStep, float* pDst, int dstPlaneStep, int dstStep, HmpprVolume dstRoiVolume, HmpprBorderType borderType, const float borderValue[1], const HmpprFilterBorderSpec* pSpec);
- Release function:
HmppResult HMPPI_FilterBorderRelease_32f(HmpprFilterBorderSpec *pSpec);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
pSrc |
Pointer to the origin of the source volume |
The value cannot be NULL. |
Input |
srcStep |
Distance between starts of consecutive lines within each plane of the source volume, in bytes |
The value must be zero or a positive integer. |
Input |
srcPlaneStep |
Distance between consecutive planes of the source volume, in bytes |
The value must be zero or a positive integer. |
Input |
pDst |
Pointer to the origin of the destination volume |
The value cannot be NULL. |
Input/Output |
dstStep |
Distance between starts of consecutive lines within each plane of the destination volume, in bytes |
The value must be zero or a positive integer. |
Input |
dstPlaneStep |
Distance between consecutive planes of the destination volume, in bytes |
The value must be zero or a positive integer. |
Input |
kernel |
Pointer to the filter kernel |
The value cannot be NULL. |
Input/Output |
kernelSize |
Filter kernel size |
Positive odd number |
Input |
kernelVolume |
Filter kernel volume |
Positive odd number |
Input |
numChannels |
Number of image channels |
1 |
Input |
pSpecSize |
Space size allocated to pSpec |
The value cannot be NULL. |
Input/Output |
dstRoiVolume |
VOI within the destination volume |
Positive integer |
Input |
borderType |
Border type |
The value is one of the following enumerated values of HmppiBorderType: HMPPI_BORDER_CONST HMPPI_BORDER_REPL HMPPR_BORDER_IN_MEM |
Input |
borderValue |
Constant value of the constant border pixel. This parameter is valid only when borderType is set to HMPPI_BORDER_CONST. |
Value within the data type range |
Input |
pSpec |
Pointer to the special structure |
The value cannot be NULL. |
Input/Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The input parameters contain a null pointer. |
HMPP_STS_SIZE_ERR |
The value of dstRoiVolume or kernelVolume is less than or equal to 0. |
HMPP_STS_STEP_ERR |
The value of srcStep, srcPlaneStep, dstStep, or dstPlaneStep is less than 0. |
HMPP_STS_CHANNEL_ERR |
The number of channels is not 1. |
HMPP_STS_OVERFLOW |
The product of the width, height, and depth of kernelVolume overflows. |
Example
void FilterBorderExample()
{
HmpprVolume kernelVolume = {3, 3, 3};
HmpprVolume dstRoiVolume = {4, 4, 4};
int pSpecSize;
HmppResult result;
HmpprFilterBorderSpec* pSpec;
float* pKernel;
float pSrc[] = {38.014484, 82.609879, 82.758270, 81.367149, 89.961128, 86.196541, 2.654759, 8.122633, 20.915607, 39.117149, 48.680553, 74.702560, 89.141975, 0.049839, 96.961235, 40.884659, 0.073048, 82.266838, 43.245163, 39.711945, 92.387321, 63.789082, 39.633656, 33.714893, 68.096214, 25.101330, 62.661972, 17.430357, 60.464512, 33.217445, 37.544556, 51.155441, 67.719810, 20.685936, 32.905922, 57.153358, 6.772291, 86.404984, 17.585430, 27.213909, 25.116919, 17.515392, 53.564182, 66.432114, 18.855532, 49.816486, 59.853039, 70.812675, 32.314438, 2.026977, 9.393250, 76.235771, 65.080223, 0.228351, 62.949459, 85.970299, 26.796694, 24.186850, 55.365528, 86.225479, 58.701576, 92.171112, 37.857521, 25.761415};
float* pDst;
HmpprBorderType borderType = HMPPR_BORDER_REPL;
int srcStep = dstRoiVolume.width * sizeof(float);
int srcPlaneStep = dstRoiVolume.width * dstRoiVolume.height * sizeof(float);
int dstStep = srcStep;
int dstPlaneStep = srcPlaneStep;
int kernelTotalSize = kernelVolume.width * kernelVolume.height * kernelVolume.depth;
pKernel = HMPPS_Malloc_32f(kernelTotalSize);
int dataTotalSize = dstRoiVolume.width * dstRoiVolume.height * dstRoiVolume.depth;
pDst = HMPPS_Malloc_32f(dataTotalSize);
result = HMPPI_FilterBorderGetSize(kernelVolume, dstRoiVolume, 1, &pSpecSize);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
pSpec = (HmpprFilterBorderSpec*)malloc(pSpecSize);
result = HMPPI_CreateKernel3D_32f(pKernel, kernelVolume);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPI_FilterBorderInit_32f(pKernel, kernelVolume, 1, pSpec);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
float borderValue = pSrc[0];
result = HMPPI_FilterBorder_32f_C1V(pSrc, srcPlaneStep, srcStep,
pDst, dstPlaneStep, dstStep,
dstRoiVolume, borderType,
&borderValue, pSpec);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
for (int i = 0; i < dataTotalSize; i++){
printf("%f ", pDst[i]);
}
HMPPI_FilterBorderRelease_32f(pSpec);
}
Output:
result = 0 result = 0 result = 0 result = 0 58.525280 59.930946 61.054619 50.821186 55.691948 54.039684 52.591640 46.378212 59.807632 52.972359 42.925503 42.069408 49.808098 51.124119 45.393032 55.123226 52.184692 51.331261 52.249077 45.508347 48.955585 48.016075 47.897266 44.273628 49.801155 47.854038 44.845074 44.447330 42.592846 46.391796 47.622082 56.376503 40.344097 37.633095 42.397793 47.313328 40.404427 40.143230 44.059200 50.277069 45.813835 45.989544 47.561592 50.238838 44.789623 46.495136 49.068993 50.859116 34.800060 29.068176 37.096851 54.951031 32.350891 32.776085 43.875008 61.288776 40.396778 43.783665 51.504829 57.929409 45.802296 48.920952 53.821930 51.945923