// Histogram balancing
Bool histogramequalize (unsigned char * pdata, unsigned int nwidth, unsigned int nheight)
{
If (pdata = NULL) return false;
Unsigned int x, y, I;
Unsigned int linestart;
Unsigned int histogram [256];
Unsigned int maptable [256];
Unsigned int tempvalue;
// Obtain the Histogram
For (I = 0; I <256; I ++)
{
Histogram [I] = 0;
Maptable [I] = 0;
}
For (y = 0; y <m_nheight; y ++)
{
Linestart = y * m_nwidth;
For (x = 0; x <m_nwidth; X ++)
{
Histogram [pdata [linestart + x] ++;
}
}
// Calculate the shadow table
Tempvalue = 0;
For (I = 0; I <256; I ++)
{
Tempvalue + = histogram [I];
Maptable [I] = tempvalue * 255/m_nwidth/m_nheight;
}
// Histogram balancing
For (y = 0; y <m_nheight; y ++)
{
Linestart = y * m_nwidth;
For (x = 0; x <m_nwidth; X ++)
{
Pdata [linestart + x] = maptable [pdata [linestart + x];
}
}
Return true;
}
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.