Filter2d

Filters (convolves) a 2D image using the specified filter kernel, where the anchor point defaults to the center of the convolution kernel.

Operator Effect

Input ImageParameterOutput Image
imagekernel=[0.003906250.0156250.027343750.0156250.003906250.0156250.06250.10156250.06250.0156250.027343750.10156250.093750.10156250.027343750.0156250.06250.10156250.06250.0156250.003906250.0156250.027343750.0156250.00390625]\begin{aligned}kernel = \begin{bmatrix} 0.00390625& 0.015625& 0.02734375& 0.015625& 0.00390625\\ 0.015625& 0.0625& 0.1015625& 0.0625& 0.015625&\\ 0.02734375& 0.1015625& 0.09375& 0.1015625& 0.02734375\\ 0.015625& 0.0625& 0.1015625& 0.0625& 0.015625\\ 0.00390625& 0.015625& 0.02734375& 0.015625& 0.00390625\end{bmatrix}\end{aligned}image

Principle

dst(x,y)=0x<kernel.cols0y<kernel.rowskernel(x,y)src(x+xanchor.x,y+yanchor.y)\begin{aligned}dst(x,y)=\sum_{\begin{aligned}0\leqslant x'<kernel.cols \\ 0\leqslant y'<kernel.rows \end{aligned}}kernel(x',y')*src(x+x'-anchor.x,y+y'-anchor.y)\end{aligned}

Among them, dstdst is the output image, kernelkernel is the filter kernel, and anchoranchor is the anchor coordinates, the default anchor is (-1, -1).

API Interface

int32_t hbVPFilter2D(hbUCPTaskHandle_t *taskHandle, hbVPImage *dstImg, hbVPImage const *srcImg, hbVPFilterKernel const *filterKernel, hbVPFilter2DParam const *filter2DParam);

For detailed interface information, please refer to hbVPFilter2D.

Usage

// Include the header #include "hobot/hb_ucp.h" #include "hobot/vp/hb_vp.h" #include "hobot/vp/hb_vp_filter2d.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 * sizeof(float32_t), 0); hbVPFilterKernel kernel; kernel.dataType = HB_VP_IMAGE_TYPE_F32C1; kernel.width = 3; kernel.height = 3; kernel.dataPhyAddr = kernel_mem.phyAddr; kernel.dataVirAddr = kernel_mem.virAddr; // init param hbVPFilter2DParam vp_param; vp_param.borderType = HB_VP_BORDER_REPLICATE; // 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 hbVPFilter2D(&task_handle, &dst_img, &src_img, &kernel, &vp_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);