Equalizehist

Histogram equalization is an image processing method that uses a histogram of the image intensity distribution for contrast adjustment.

Operator Effect

Input ImageParameterOutput Image
image-image

Principle

To achieve the equalization effect, the image needs to be remapped and its cumulative distribution function is calculated as follows:

H(i)=0j<iH(j)H'(i)=\displaystyle\sum_{0\leqslant j<i}H(j)

where H is the input histogram.

After obtaining the cumulative distribution it needs to be normalized to obtain the functional form as follows:

image

Finally the equalized image is obtained using the remapping function, which is as follows:

dst(x,y)=H(src(x,y))dst(x,y)=H'(src(x,y))

API Interface

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

For detailed interface information, please refer to hbVPEqualizeHist.

Usage

// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_equalize_hist.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 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
hbVPEqualizeHist(&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);