Gaussian Blur

Gaussian filtering uses a specific filter kernel to convolve the image and is a linear smoothing filter that is widely used in the noise removal process of image processing.

Operator Effect

Input ImageParameterOutput Image
imagekernelSize = 3image

Principle

The 3X3 Gaussian filter kernel is as follows:

kernel=116[121242121]\begin{aligned}kernel = \frac{1}{16}\begin{bmatrix} 1 & 2 & 1 \\2 & 4 & 2 \\1 & 2 & 1 \end{bmatrix}\end{aligned}

The 5X5 Gaussian filter kernel is as follows:

kernel=1256[1464141624164624362464162416414641]\begin{aligned}kernel = \frac{1}{256}\begin{bmatrix}1 & 4 & 6 & 4 & 1 \\4 & 16 & 24 & 16 & 4 \\6 & 24 & 36 & 24 & 6 \\4 & 16 & 24 & 16 & 4 \\1 & 4 & 6 & 4 & 1 \end{bmatrix}\end{aligned}

API Interface

int32_t hbVPGaussianBlur(hbUCPTaskHandle_t *taskHandle,, hbVPImage *dstImg, hbVPImage const *srcImg, hbVPGaussianBlurParam const *gaussianParam);

For detailed interface information, please refer to hbVPGaussianBlur.

Usage

// Include the header #include "hobot/hb_ucp.h" #include "hobot/vp/hb_vp.h" #include "hobot/vp/hb_vp_gaussian_blur.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 param hbVPGaussianBlurParam vp_param; vp_param.kernelSize = 3; 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 hbVPGaussianBlur(&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);