Digital image of histogram equalization (CC ++ source code)

xiaoxiao2021-03-06  65

The histogram equalization of digital images is commonly used image enhancement method because equalization is automated without manual intervention, and often gets more satisfactory results. The following program uses the function provided by OpenCV to implement this function. Support for OpenCV B4.0, compiling under VC6. /// perform histgram equalization for single channel image // Assuredigit Sample Code //

#include "cv.h" #include "highgui.h"

#define hdim 256 // bin of hist, default = 256

INT Main (int Argc, char ** argv) {iplimage * src = 0, * DST = 0; cvhistogram * hist = 0; int N = hdim; double nn [hdim]; uchar t [hdim]; cvmat * t_mat; INT x; int sum = 0; // sum of pixels of the source image of the sum of the quadprints in the image; if (argc! = 2 || (src = CVLoadImage (Argv [1], 0)) == null) // force to gray image return -1; cvnamedwindow ("Source", 1); cvnamedwindow ("result", 1); // calculate histgram calculation histogram Hist = CVCREATEHIST (1, & n, cv_hist_Array, 0 , 1); Cvcalchist (& SRC, HIST, 0, 0); // Create Accumulative Distribute Function of Histgram Val = 0; for (x = 0; x Bins , x); nn [x] = val;}

// compute intersity Transformation Calculation of discrete forms of transformation functions SUM = src-> height * src-> width; for (x = 0; x

// do INTENSITY TRANSFORM for Source Image DST = CVCLONEIMAGE (SRC); t_mat = CvcreateMatheader (1, 256, CV_8UC1); CVSETDATA (T_MAT, T, 0); // Directly Use Look-Up-Table Function Directly calls internal functions Look-up-Table process CVLUT (SRC, DST, T_MAT);

cvShowImage ( "source", src); cvShowImage ( "result", dst); cvWaitKey (0); cvDestroyWindow ( "source"); cvDestroyWindow ( "result"); cvReleaseImage (& src); cvReleaseImage (& dst); cvReleaseHist (& hist RETURN 0;}

转载请注明原文地址:https://www.9cbs.com/read-106617.html

New Post(0)