Laplacian Filter

Laplacian filter is a second derivative operator commonly used in image processing, mainly for edge detection. It highlights regional changes in an image by calculating the second derivative of the image grayscale value. Since it is very sensitive to noise, the image is usually first Gaussian smoothed to reduce the impact of noise. The calculation of the Laplacian operator involves a convolution kernel on the image to obtain the second-order derivative value of each pixel in the image. These values ​​represent the rate of change of the pixel value in the image. This process can effectively detect the edges in the image.

Operator Effect

Input ImageParameterOutput Image
imagekernelSize = 1
borderType = HB_VP_BORDER_CONSTANT
normalize = 0
image

Principle

The main calculation process of Laplacian filter is to convolve the input image using a specific filter kernel. The main formula is as follows:

dst=Δsrc=2srcx2+2srcy2{dst} = \Delta \text{src} = \frac{\partial^2 \text{src}}{\partial x^2} + \frac{\partial^2 \text{src}}{\partial y^2}

The dstdst is the output image, srcsrc is the input image. Currently vp only supports OpenCV ksize = 1, [0, 1, 0, 1, -4, 1, 0, 1, 0].

API Interface

int32_t hbVPLaplacianFilter(hbUCPTaskHandle_t *taskHandle, hbVPImage *dstImg, hbVPImage const *srcImg, hbVPLaplacianFilterParam const *laplacianParam);

For detailed interface information, please refer to hbVPLaplacianFilter.

Usage

// Include the header // Include the header #include "hobot/hb_ucp.h" #include "hobot/vp/hb_vp.h" #include "hobot/vp/hb_vp_bilateral_filter.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_S16C1, dst_width, dst_height, dst_stride, dst_mem.virAddr, dst_mem.phyAddr, nullptr, 0, 0}; // init param hbVPLaplacianFilterParam vp_param; vp_param.kernelSize = 3; vp_param.borderType = HB_VP_BORDER_CONSTANT; vp_param.normalize = 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 hbVPLaplacianFilter(&task_handle, &dst_img, &src_img, &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);