C + + histogram matching algorithm code

Source: Internet
Author: User

/*-------------------------------------------------------------------------*///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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.