/*-------------------------------------------------------------------------*///function Name: Histeq ()//Incoming parameters://Byte*dstdata to match the grayscale image memory space//double the histogram of the *srcarray template accumulates and is normalized with a size of//int M_width The width of the matching memory space//int M_height The height of the matching memory space//int M_pitch The memory size of each row that matches the memory space/*-------------------------------------------------------------------------*/voidHisteq (Byte*dstdata,Double*srcarray,intM_width,intM_height,intM_pitch) { Doubledsthist[ the]; memset (Dsthist,0, the*sizeof(Double)); inti,j; Doubledstarray[ the]; memset (Dstarray,0, the*sizeof(Double)); //Statistical Histogram for(i =0; I < m_height;i++) { for(j =0; J < m_width;j++) {dsthist[(int) dstdata[i * M_pitch + j]]++; } } //Calculate histogram accumulation DoubleM_bytes = M_width *M_height; dstarray[0] = dsthist[0]; for(i =1; I < the; i++) {Dstarray[i]= Dstarray[i-1] +Dsthist[i]; } //Normalization of histogram accumulation for(i =0; I < the; i++) {Dstarray[i]/=m_bytes; } //Histogram matching DoubleM_DIFFA,M_DIFFB; intK =0; BYTE mappixel[ the]; memset (Mappixel,0, the*sizeof(BYTE)); for(i =0; I < the; i++) {M_DIFFB=1; for(j = k; J < the; j + +) {M_diffa= ABS (Dstarray[i]-Srcarray[j]); if(M_DIFFA-M_DIFFB <1.0E-5) {M_DIFFB=M_diffa; K=J; } Else{k= J-1; Break; } } if(k = =255) { for(intL = I;l < the; l++) {Mappixel[l]=(BYTE) k; } Break; } Mappixel[i]=(BYTE) k; } //target Image Lookup Index Table for(i =0; I < m_height;i++) { for(j =0; J < m_width;j++) {Dstdata[i* M_pitch + j] = Mappixel[dstdata[i * M_pitch +J]]; } }}
Source Address: http://blog.csdn.net/hcx25909/article/details/7090921
C + + histogram matching algorithm code