Dilate

The dilation (expansion) algorithm performs a two-dimensional filtering operation on the input image using the supplied 2D Boolean kernel; the kernel size of the Boolean defines the pixel neighborhood of the filtering operation. As a morphological operation operator, equivalent to the maximize operation, which increases or enlarges the foreground area in the picture (in this case, the white color in the figure below). Identifies and fills holes in the picture.

Operator Effect

Input ImageParameterOutput Image
image-image

Principle

dst(x,y)=max0i<kwidth0j<kheightsrc(xkwidth2+i,ykheight2+j)\begin{aligned}dst(x,y)=\max_{\begin{aligned} 0 \leqslant i<kwidth \\ 0 \leqslant j < kheight\end{aligned}} src(x-\lfloor\frac{kwidth}{2}\rfloor+i,y-\lfloor\frac{kheight}{2}\rfloor+j)\end{aligned}

Morphological operations are a set of image processing operations that process digital images based on the shape of the image. The dilation filter is equivalent to the max operation and will expand the bright structures in the image. Another morphological filter is Erode, which is equivalent to the minimization operation. An erosion filter may be used after an expansion filter to form a morphological closure of the image.

API Interface

int32_t hbVPDilate(hbUCPTaskHandle_t *taskHandle, hbVPImage *dstImg, hbVPImage const *srcImg, hbVPFilterKernel const *dilateKernel, hbVPDilateParam const *dilateParam);

For detailed interface information, please refer to hbVPDilate.

Usage

// Include the header #include "hobot/hb_ucp.h" #include "hobot/vp/hb_vp.h" #include "hobot/vp/hb_vp_dilate.h" // init Image, allocate memory for image data hbUCPSysMem src_mem; hbUCPMallocCached(&src_mem, src_stride * src_height, 0); hbVPImage src_img{HB_VP_IMAGE_FORMAT_Y, HB_VP_IMAGE_TYPE_U8C1, src_width, src_height, src_stride, src_mem.virAddr, src_mem.phyAddr, nullptr, 0, 0}; hbUCPSysMem dst_mem; hbUCPMallocCached(&dst_mem, dst_stride * dst_height, 0); hbVPImage dst_img{HB_VP_IMAGE_FORMAT_Y, HB_VP_IMAGE_TYPE_U8C1, dst_width, dst_height, dst_stride, dst_mem.virAddr, dst_mem.phyAddr, nullptr, 0, 0}; // init kernel hbUCPSysMem kernel_mem; hbUCPMallocCached(&kernel_mem, 3 * 3, 0); hbVPFilterKernel kernel; kernel.dataType = HB_VP_IMAGE_TYPE_U8C1; kernel.width = 3; kernel.height = 3; kernel.dataPhyAddr = kernel_mem.phyAddr; kernel.dataVirAddr = kernel_mem.virAddr; // init param hbVPDilateParam dilate_param; dilate_param.pointLocX = -1; dilate_param.pointLocY = -1; dilate_param.iterations = 1; dilate_param.borderType = 0; dilate_param.borderValue = 0; // init task handle and schedule param hbUCPTaskHandle_t task_handle{nullptr}; hbUCPSchedParam sched_param; HB_UCP_INITIALIZE_SCHED_PARAM(&sched_param); sched_param.backend = HB_UCP_DSP_CORE_0; // create task hbVPDilate(&task_handle, &dst_img, &src_img, &kernel, &dilate_param); // submit task hbUCPSubmitTask(task_handle, &sched_param); // wait for task done hbUCPWaitTaskDone(task_handle, 0); // release task handle hbUCPReleaseTask(task_handle); // release memory hbUCPFree(&src_mem); hbUCPFree(&dst_mem); hbUCPFree(&kernel_mem);