Created
April 23, 2013 15:16
-
-
Save uugan/5444434 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Histogram hyperbolic equalization */ | |
| float hyperbolic_histogram(unsigned char* inbuf, unsigned char* outbuf, int height,int width){ | |
| double g_min=255; | |
| double g_max=0; | |
| double* histogram = new double[256]; | |
| double* cdf = new double[256]; /* generates Pf(f) */ | |
| double* out = new double[height*width]; /* output array of doubles */ | |
| int start = GetTickCount(); | |
| for(int i=0;i<256;i++) { | |
| histogram[i] = 0; | |
| out[i]=0; | |
| } | |
| double d=1.0/(double)(height*width); /* for histogram counter */ | |
| for(int i=0;i<height;i++){ | |
| for(int j=0;j<width;j++) | |
| { | |
| if(inbuf[i*width+j]<g_min && inbuf[i*width+j]!=0) | |
| g_min = inbuf[i*width+j]; | |
| if(inbuf[i*width+j]>g_max) | |
| g_max = inbuf[i*width+j]; | |
| histogram[inbuf[i*width+j]]+=d; | |
| } | |
| } | |
| cdf[0]=histogram[0]; | |
| for(int i=1;i<256;i++) | |
| cdf[i]=(cdf[i-1]+histogram[i]); /* Pf(f) process of cumsuming */ | |
| double max=-999,min=999; | |
| for(int i=0;i<height;i++){ | |
| for(int j=0;j<width;j++){ | |
| /*Finding output double values */ | |
| out[i*width+j] = g_min*pow(g_max/g_min,(cdf[inbuf[i*width+j]])); | |
| /*Finding max and min values from this double array for change to unsigned char */ | |
| if(out[i*width+j]>max)max=out[i*width+j]; | |
| if(out[i*width+j]<min)min=out[i*width+j]; | |
| } | |
| } | |
| /* double array to unsigned char */ | |
| for(int i=0;i<height;i++) | |
| for(int j=0;j<width;j++) | |
| outbuf[i*width+j]=(unsigned char)(out[i*width+j]-min)/(max-min)*255; | |
| return (float)(GetTickCount()-start); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment