PyrUp

Pyrup算子通过平滑、采样等流程将图片进行上采样,生成长宽为原图两倍大小的图片,常用于构建图像金字塔、获取高分辨率原图等场景。

算子效果

输入图像参数输出图像
image-image

原理

上采样的实现流程为先对原图进行扩充,在原图的偶数行列上插入0,再对图像进行高斯平滑,最终得到目标图像。长宽符合以下约束:

dst.width=src.width2dst.width=src.width*2

dst.height=src.height2dst.height=src.height*2

在高斯平滑阶段,使用的高斯滤波核如下:

kernel=164[1464141624164624362464162416414641]\begin{aligned}kernel = \frac{1}{64}\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接口

int32_t hbVPPyrUp(hbUCPTaskHandle_t *taskHandle,
                  hbVPImage *dstImg,
                  hbVPImage const *srcImg);

详细接口信息请查看 hbVPPyrUp

使用方法

// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_pyr_up.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};

int32_t dst_width{src_width * 2};
int32_t dst_height{src_height * 2};
int32_t dst_stride{src_stride};

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 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
hbVPPyrUp(&task_handle, &dst_img, &src_img);

// 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);