//直方图均衡 void Equalize(u8 **img, u16 height, u16 width) { //循环变量 u16 i,j; //临时变量 u16 lTemp; //映射表 u16 bMap[256]; //直方图 long lCount[256]; //清零直方图 for (i = 0; i < 256; i ++) { lCount[i] = 0; } //直方图统计 for (i = 0; i < height; i ++) { for (j = 0; j < width; j ++) { lCount[img[i][j] ]++; } } //计算灰度映射表 for (i = 0; i < 256; i++) { lTemp = 0; for (j = 0; j <= i ; j++) { lTemp += lCount[j]; } //计算映射表 bMap[i] = (u16) (lTemp * 255 / height / width); } //根据映射表填充图像 for(i = 0; i < height; i++) { for(j = 0; j < width; j++) { // img[height - 1 - i][j] = bMap[(height - 1 - i)*width + j]; } } }
各位懂的帮俺看看呗!