以下是自动对比度调整的函数,填空完成。/*输入参数:unsigned char *img8位灰度图像位图数据首地址int count图像像素个数输出参数:unsigned char *img8位灰度图像位图数据首地址功能:8位灰度图像的自动对比度调整*/void AutoContrast(unsigned char *img,int count){//求取图像中的最小像素值和最大像素值int grayLow = 255, grayHigh = 0;int i;unsigned char *p = img;for(i = 0; i < count; i++){if(*p < grayLow) grayLow = *p;if(*p > grayHigh) grayHigh = *p;p++;}if(grayHigh - grayLow == 0)return;//图像中的灰度值均相等,无法进行自动对比度调整//自动对比度映射p = img;for(i = 0; i < count; i++){*p++ = (*p - ______________) *255/ ( ______________ - grayLow );}}
查看答案
以下是直方图均衡化的函数,请填空完成/*输入参数:unsigned char *img8位灰度图像位图数据首地址int count图像像素个数输出参数:unsigned char *img8位灰度图像位图数据首地址功能:8位灰度图像的直方图均衡化*/void Equalize(unsigned char *img, int count){int i;unsigned char *p = img;//统计累积直方图int hist[256];memset(hist,0,256*sizeof(int));for(i = 0; i < count; i++){hist[*p++]++;}for(i = 1; i < 256;i++){hist[i] += ________________;}//逐点替换for(i = 0; i < count; i++){*img = 255 * ____________/ count;img++;}}
以下是修正的自动对比度增强算法的实现,请填空完成/*输入参数:unsigned char *img8位灰度图像位图数据首地址int count图像像素个数double percent 上下限像素个数百分比输出参数:unsigned char *img8位灰度图像位图数据首地址功能:8位灰度图像的修正的自动对比度增强*/void AutoContrast(unsigned char *img, int count, double percent){int i;unsigned char *p = img;//统计累积直方图int cvHist[256];memset(cvHist,0,256*sizeof(int));for(i = 0; i < count; i++){cvHist[__________]++;}for(i = 1; i < 256;i++){cvHist[i] += ______________;}//计算近似最小和最大灰度int lowCount, highCount, grayLow,grayHigh;lowCount = percent * ___________;highCount= (1 - percent) *count;for(i = 0; i< 256;i++){if(cvHist[i] > lowCount){grayLow = i;break;}}for(i = 255; i >=0; i--){if(cvHist[i] <= ___________){grayHigh= i;break;}}if(grayHigh <= grayLow)return;//图像中的灰度值均相等,无法进行自动对比度调整//自动对比度映射p = img;for(i = 0; i < count; i++){if(*p >= grayHigh )*p = __________________;else if(*p <= grayLow)*p = 0;else*p = (___________- grayLow) *255/ ( grayHigh - grayLow );p++;}}
以下是用LUT实现的直方图均衡算法函数,请填空完成/*输入参数:unsigned char *img8位灰度图像位图数据首地址int count图像像素个数输出参数:unsigned char *img8位灰度图像位图数据首地址功能:8位灰度图像的直方图均衡化*/void Equalize(unsigned char *img,int count){int i;unsigned char *p = img;//统计直方图int hist[256];memset(hist,0,256*sizeof(int));for(i = 0; i < count; i++){hist[*p++]++;}//计算映射关系unsigned char LUT[256];int H = 0;for(i = 0; i < 256;i++){H += ___________;LUT[i] = 255 * H / ___________;}//逐点替换for(i = 0; i < count; i++){*img = LUT[_______];img++;}}
以下是用LUT实现的自动对比度调整算法,请填空完成。/*输入参数:unsigned char *img8位灰度图像位图数据首地址int count图像像素个数输出参数:unsigned char *img8位灰度图像位图数据首地址功能:8位灰度图像的自动对比度增强*/void AutoContrast(unsigned char *img,int count){//求取图像中的最小像素值和最大像素值int grayLow = 255, grayHigh = 0;int i;unsigned char *p = img;for(i = 0; i < count; i++){if(*p < grayLow) grayLow = *p;if(*p > grayHigh) grayHigh = *p;p++;}if(grayHigh - grayLow == 0)return;//图像中的灰度值均相等,无法进行自动对比度调整unsigned char LUT[256];for(i = 0; i < 256;i++){LUT[i] = (i - _____________) *255/ ( grayHigh - grayLow );}//自动对比度映射p = img;for(i = 0; i < count; i++){*p++ =________________;}}