MorphReconstructDilate
Reconstructs an image by dilation.
The function is called as follows:
- Call the Init function to initialize the buffer required for executing the main function. Otherwise, the main function cannot be called successfully.
- Call the main function.
- Release the buffer by calling Release.
The function interface declaration is as follows:
- Initialization:
HmppResult HMPPI_MorphReconstructInit_32f(HmppiSize roiSize, HmppDataType dataType, int32_t numChannels, float **buffer);
HmppResult HMPPI_MorphReconstructInit_8u(HmppiSize roiSize, HmppDataType dataType, int32_t numChannels, uint8_t **buffer);
- Main functions:
HmppResult HMPPI_MorphReconstructDilate_8u_C1IR(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, uint8_t *buffer, HmppiNorm Norm);
HmppResult HMPPI_MorphReconstructDilate_16u_C1IR(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, uint8_t *buffer, HmppiNorm Norm);
HmppResult HMPPI_MorphReconstructDilate_64f_C1IR(const double *src, int32_t srcStep, double *dst, int32_t dstStep, HmppiSize roiSize, uint8_t *buffer, HmppiNorm Norm);
HmppResult HMPPI_MorphReconstructDilate_32f_C1IR(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, float *buffer, HmppiNorm Norm);
- Memory release:
HmppResult HMPPI_MorphReconstructRelease_8u(uint8_t *buffer);
HmppResult HMPPI_MorphReconstructRelease_32f(float *buffer);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
dataType |
Data type of the source image (which is the same as that of the destination image) |
Enumeration. Possible values are HMPP8U, HMPP16U, HMPP32F, and HMPP64F. |
Input |
numChannels |
Number of channels for the source image (which is the same as that for the destination image) |
Only 1, 3, and 4 channels are supported. |
Input |
src |
Pointer to the source image |
The value cannot be NULL. |
Input |
srcStep |
Distance between starts of consecutive lines in the source image, in bytes |
The value must be a non-negative integer multiple of the bytes of src's data type. |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
dstStep |
Distance between starts of consecutive lines in the destination image, in bytes |
The value must be a non-negative integer multiple of the bytes of dst's data type. |
Input |
roiSize |
Size of the ROI of the source and destination images, in pixels |
roiSize.width ∈ (0, INT_MAX], roiSize.height ∈ (0, INT_MAX] |
Input |
Norm |
Type of the norm to form the mask |
HMPP_NORMINF: infinity norm (8-connectivity, 3 x 3 rectangular mask) HMPP_NORML1: L1 norm (4-connectivity, 3 x 3 cross mask) |
Input |
buffer (in the Init function) |
Pointer to the pointer of the auxiliary buffer |
The value cannot be NULL. |
Output |
buffer (in the main and release functions) |
Pointer to the auxiliary buffer. |
The value cannot be NULL. |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
Any of the specified pointers is NULL. |
HMPP_STS_SIZE_ERR |
The value of roiSize or maskSize is 0 or negative. |
HMPP_STS_NOT_SUPPORTED_MODE_ERR |
The specified data type is not supported for initialization. |
HMPP_STS_NUMCHANNELS_ERR |
The specified number of channels is not supported for initialization. |
HMPP_STS_STEP_ERR |
The value of srcStep or dstStep is 0 or negative. |
HMPP_STS_MALLOC_FAILED |
The Init function failed to allocate the memory required by the algorithm model. |
HMPP_STS_NOT_EVEN_STEP_ERR |
The value of srcStep or dstStep is not an integer multiple of the bytes of the involved image's data type. |
HMPP_STS_ROI_ERR |
The width and height of the source or destination image are smaller than those specified by roiSize. |
HMPP_STS_NORM_ERR |
The mask norm type is not supported. |
The main functions of the 8u, 16u, and 64f types use the 8u initialization interface, and the main function of the 32f type uses the 32f initialization interface. If other interfaces are used, the system may break down when the main function is called.
Example
#define SRC_BUFFER_SIZE_T 96
#define DST_BUFFER_SIZE_T 64
#define MASK_BUFFER_SIZE_T 12
void MorphReconstructDilateExample()
{
HmppiSize roiSize = { 4, 4 };
const uint16_t src[SRC_BUFFER_SIZE_T] = {
11, 12, 13, 14, 15, 16, 17, 18, 12, 19, 13, 15,
21, 22, 23, 24, 25, 26, 27, 28, 22, 29, 23, 25,
31, 32, 33, 34, 35, 36, 37, 38, 32, 39, 33, 35,
41, 42, 43, 44, 45, 46, 47, 48, 42, 49, 43, 45,
51, 52, 53, 54, 55, 56, 57, 58, 52, 59, 53, 55,
61, 62, 63, 64, 65, 66, 67, 68, 62, 69, 63, 65,
71, 72, 73, 74, 75, 76, 77, 78, 72, 79, 73, 75,
81, 82, 83, 84, 85, 86, 87, 88, 82, 89, 83, 85
};
uint16_t dst[DST_BUFFER_SIZE_T] = { 0 };
HmppiSize maskSize = { 4, 3 };
uint8_t mask[MASK_BUFFER_SIZE_T] = {
1, 0, 2, 3,
5, 1, 1, 0,
0, 2, 0, 6,
};
const int32_t srcWidth = 12;
const int32_t dstWidth = 8;
int32_t srcStep = srcWidth * sizeof(int16_t);
int32_t dstStep = dstWidth * sizeof(int16_t);
HmppDataType dataType = HMPP16U;
int32_t numChannels = 1;
uint8_t *buffer = NULL;
HmppiNorm Norm = HMPP_NORMINF;
HmppResult result;
result = HMPPI_MorphReconstructInit_8u(roiSize, dataType, numChannels, &buffer);
printf("HMPPI_MorphReconstructInit_8u result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPI_MorphReconstructDilate_16u_C1IR(src, srcStep, dst, dstStep, roiSize, buffer, Norm);
printf("HMPPI_MorphReconstructDilate_16u_C1IR result = %d\n", result);
(void)HMPPI_MorphReconstructRelease_8u(buffer);
buffer = NULL;
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("result = %d \ndst = ", result);
if (result != HMPP_STS_NO_ERR) {
printf("result error: %d\n", result);
}
for (int32_t i = 0; i < DST_BUFFER_SIZE_T; ++i) {
if (i % dstWidth == 0) {
printf("\n");
}
printf("%3d ", dst[i]);
}
printf("\n");
}
int main(void)
{
MorphReconstructDilateExample();
return 0;
}
Output:
HMPPI_MorphReconstructInit_8u result = 0 HMPPI_MorphReconstructDilate_16u_C1IR result = 0 result = 0 dst = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0