直方图均衡化

来源:互联网 发布:星巢网络c5 编辑:程序博客网 时间:2024/06/05 23:23

 

max = 255 

min = 0

 

 

void  HistogramDrawDlg::HistogramAvge(){  if(m_himageDib.m_nBitCount != 8)  return  ;  if(m_pImgDataOut != NULL){    delete  [] m_pImgDataOut ;m_pImgDataOut = NULL  ;  }  if(m_lpColorTableOut != NULL){  delete []m_lpColorTableOut ;  m_lpColorTableOut = NULL ;  }  m_nBitCountOut = m_himageDib.m_nBitCount ;  m_nColorTableLengthOut = m_himageDib.ComputeColorTabalLength(m_nBitCountOut) ;  if(m_nColorTableLengthOut != 0){    m_lpColorTableOut = new RGBQUAD[m_nColorTableLengthOut] ;memcpy(m_lpColorTableOut , m_himageDib.m_lpColorTable ,    sizeof(RGBQUAD) * m_nColorTableLengthOut) ;  }  m_imgWidthOut = m_himageDib.m_imgWidth ;  m_imgHeightOut = m_himageDib.m_imgHeight ;  int lineBite = (m_imgWidthOut * m_nBitCountOut / 8 + 3) / 4 * 4 ;  m_pImgDataOut = new unsigned char[m_imgHeightOut * lineBite] ;  int to[256] ;  ComputeHistGray() ;  double sum = 0  , A = m_imgHeightOut * m_imgWidthOut  ;   for(int i = 0 ; i < 256 ; i++){    sum += m_histArry[i] ;to[i] = sum * 255 / A + 0.5 ;  }  for(int i = 0 ; i < m_imgHeightOut ; i++){  for(int j = 0 ; j < m_imgWidthOut ; j++){       *(m_pImgDataOut + i * lineBite + j) =   to[*(m_himageDib.m_pImgData + i * lineBite + j)] ;  }  }}


 

 

 

0 0