计算每一个 像素值出现的次数
for(int y = 0; y < m_image->GetHeight(); y++)
{
for(int x = 0; x < m_image->GetWidth();x++)
{
COLORREF rgb = m_image->GetPixel(x,y);
int rValue = GetRValue(rgb); // 记录每一个像素出现次数。
hist[rValue]++;
}
}
计算归一化直方图和累计直方图
int hist[256] = {0};
double phist[256];
for (int i = 0; i <= 255 ;i++)
{
phist [i] = (double) hist[i] / (m_image->GetHeight() * m_image->GetWidth()); //归一化直方图 即每个像素出现概率
}
double dSum[256] = {0.0};
for(int i = 0; i<=255;i++)
{
if(i != 0)
{
dSum[i] = dSum[i-1] + phist[i];
}
else//累积直方图
{
dSum[i] = phist[i];
}
}
for(int y = 0; y < m_image->GetHeight(); y++)
{
for(int x = 0; x < m_image->GetWidth();x++)
{
COLORREF rgb = m_image->GetPixel(x,y);
int rValue = GetRValue(rgb);
rValue = Mapping[rValue]; //根据映射关系实现均衡化
rgb = RGB(rValue,rValue,rValue);
m_image->SetPixel(x,y,rgb);
}
}