图像增强 直方图匹配(规定化)Histogram Specification

/******************************************************************************************** 直方图基本操作 *******************************************************************************************/void InitMappingTable(void * arry,int size,int Data_type){if(Data_type==TABLE_INT)for(int i=0;i<size;i++)((int*)arry)[i]=0;else if(Data_type==TABLE_CHAR)for(int i=0;i<size;i++)((char*)arry)[i]=0;else if(Data_type==TABLE_DOUBLE)for(int i=0;i<size;i++)((double*)arry)[i]=0;}void InitHistogram(int *hist){for(int i=0;i<GRAY_LEVEL;i++)hist[i]=0;}void setHistogram(double *src,int *hist,int width,int height){InitHistogram(hist);for(int j=0;j<height;j++)for(int i=0;i<width;i++){int tempv=src[j*width+i];hist[tempv]++;}}int findHistogramMax(int *hist){for(int i=GRAY_LEVEL-1;i>=0;i–){if(hist[i]!=0)return i;}return -1;}int findHistogramMin(int *hist){for(int i=0;i<GRAY_LEVEL;i++){if(hist[i]!=0)return i;}return -1;}void fillMaptable(double * map){for(int i=1;i<GRAY_LEVEL;i++){if(map[i]==0)map[i]=map[i-1];}}/******************************************************************************************** 直方图归一化 *******************************************************************************************/void HistogramSpecification(double *src,double *dst,int* hist,int width,int height){int src_hist[GRAY_LEVEL];setHistogram(src, src_hist, width, height);double srcMap[GRAY_LEVEL];double histMap[GRAY_LEVEL];InitMappingTable(srcMap,GRAY_LEVEL,TABLE_DOUBLE);EqualizationHist(src_hist, srcMap);EqualizationHist(hist, histMap);int histMap_[GRAY_LEVEL];InitHistogram(histMap_);for(int i=0;i<GRAY_LEVEL;i++)histMap_[(int)histMap[i]]=i;double dstMap[GRAY_LEVEL];for(int i=0;i<GRAY_LEVEL;i++){dstMap[i]=histMap_[(int)srcMap[i]];}fillMaptable(dstMap);for(int i=0;i<width;i++)for(int j=0;j<height;j++)dst[j*width+i]=dstMap[(int)src[j*width+i]];}

,父母养我不容易,我在学校争口气。

图像增强 直方图匹配(规定化)Histogram Specification

相关文章:

你感兴趣的文章:

标签云: