展开全部
参考一下这个程序:
#define IMAGEWIDTH 80
#define IMAGEHEIGHT 80
void Histogram(unsigned char *pImage,int nWidth,int nHeight,float fHisto[256]);
void Enhance(unsigned char *pImage,unsigned char *pImage1,int nWidth,int nHeight,float fHisto[256],float fHisto1[256]);
unsigned char dbImage[IMAGEWIDTH*IMAGEHEIGHT];
unsigned char dbTargetImage[IMAGEWIDTH*IMAGEHEIGHT];
float fHistogram[256],fHistogram1[256];
unsigned char lut[256];
/* 直方图统计程序 */
int main()
{
... //准备一幅灰度图片到dbImage
Histogram(dbImage,IMAGEWIDTH,IMAGEHEIGHT,fHistogram); //做直方图统计
Enhance(dbImage,dbTargetImage,IMAGEWIDTH,IMAGEHEIGHT,fHistogram,fHistogram1); //直方图增强输出到dbTargetImage
...//完成后显示
}
void Histogram(unsigned char *pImage,int nWidth,int nHeight,float fHisto[256])
{
int i,j;
unsigned int uWork;
unsigned char *pWork;
for ( i=0;i<256;i++ ) fHisto[i]=0.0f;
pWork=pImage;
for ( i=0;i<nHeight;i++ )
{
for ( j=0;j<nWidth;j++,pWork++ )
{
uWork=(unsigned int)(*pWork);
fHisto[uWork]++;
}
}
uWork=nWidth*nHeight;
for ( i=0;i<256;i++ )
{
fHisto[i]/=uWork;
fHisto[i]*=100;
}
}
void Enhance(unsigned char *pImage,unsigned char *pImage1,int nWidth,int nHeight,float fHisto[256],float fHisto1[256])
{
int i,j;
unsigned int uWork;
unsigned char *pWork,*pWork1;
for ( i=0;i<256;i++ )
fHisto1[i]=fHisto[i]/100;
for ( i=1;i<256;i++ )
fHisto1[i]+=fHisto1[i-1];
for ( i=0;i<256;i++ )
lut[i]=fHisto1[i]*256;
for ( i=0;i<256;i++ )
if ( lut[i]>=256 )
lut[i]=255;
pWork=pImage; pWork1=pImage1;
for ( i=0;i<nHeight;i++ )
for ( j=0;j<nWidth;j++,pWork++,pWork1++ )
(*pWork1)=lut[(*pWork)];
}
#define IMAGEWIDTH 80
#define IMAGEHEIGHT 80
void Histogram(unsigned char *pImage,int nWidth,int nHeight,float fHisto[256]);
void Enhance(unsigned char *pImage,unsigned char *pImage1,int nWidth,int nHeight,float fHisto[256],float fHisto1[256]);
unsigned char dbImage[IMAGEWIDTH*IMAGEHEIGHT];
unsigned char dbTargetImage[IMAGEWIDTH*IMAGEHEIGHT];
float fHistogram[256],fHistogram1[256];
unsigned char lut[256];
/* 直方图统计程序 */
int main()
{
... //准备一幅灰度图片到dbImage
Histogram(dbImage,IMAGEWIDTH,IMAGEHEIGHT,fHistogram); //做直方图统计
Enhance(dbImage,dbTargetImage,IMAGEWIDTH,IMAGEHEIGHT,fHistogram,fHistogram1); //直方图增强输出到dbTargetImage
...//完成后显示
}
void Histogram(unsigned char *pImage,int nWidth,int nHeight,float fHisto[256])
{
int i,j;
unsigned int uWork;
unsigned char *pWork;
for ( i=0;i<256;i++ ) fHisto[i]=0.0f;
pWork=pImage;
for ( i=0;i<nHeight;i++ )
{
for ( j=0;j<nWidth;j++,pWork++ )
{
uWork=(unsigned int)(*pWork);
fHisto[uWork]++;
}
}
uWork=nWidth*nHeight;
for ( i=0;i<256;i++ )
{
fHisto[i]/=uWork;
fHisto[i]*=100;
}
}
void Enhance(unsigned char *pImage,unsigned char *pImage1,int nWidth,int nHeight,float fHisto[256],float fHisto1[256])
{
int i,j;
unsigned int uWork;
unsigned char *pWork,*pWork1;
for ( i=0;i<256;i++ )
fHisto1[i]=fHisto[i]/100;
for ( i=1;i<256;i++ )
fHisto1[i]+=fHisto1[i-1];
for ( i=0;i<256;i++ )
lut[i]=fHisto1[i]*256;
for ( i=0;i<256;i++ )
if ( lut[i]>=256 )
lut[i]=255;
pWork=pImage; pWork1=pImage1;
for ( i=0;i<nHeight;i++ )
for ( j=0;j<nWidth;j++,pWork++,pWork1++ )
(*pWork1)=lut[(*pWork)];
}
来自:求助得到的回答
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
东莞大凡
2024-11-19 广告
2024-11-19 广告
作为东莞市大凡光学科技有限公司的工作人员,对于halcon标定板有所了解。Halcon标定板是高精度相机标定的关键工具,通常采用实心圆点或方格作为标志点。我们公司提供的halcon标定板,具有高精度、稳定可靠的特点,适用于机器视觉领域的各种...
点击进入详情页
本回答由东莞大凡提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询