Skip to content

Instantly share code, notes, and snippets.

@uugan
Created April 23, 2013 15:07
Show Gist options
  • Save uugan/5444360 to your computer and use it in GitHub Desktop.
Save uugan/5444360 to your computer and use it in GitHub Desktop.
/* Histogram 2/3 degrees */
float hyperbolic_cube_root(unsigned char* inbuf, unsigned char* outbuf, int height, int width){
int g_min=255;
int g_max=0;
double* histogram = new double[256]; /* histogram array 0..255*/
double* cdf = new double[256]; /*Pf(f) cumulative distrib function */
double* out = new double[height*width];
int start = GetTickCount();
for(int i=0;i<256;i++) {
histogram[i] = 0;
out[i]=0;
}
/* Counting histogram values */
double d=1.0/(double)(height*width);
for(int i=0;i<height;i++){
for(int j=0;j<width;j++)
{
if(inbuf[i*width+j]<g_min) 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;
}
}
/*Counting Pf(f) function [cumsum]*/
cdf[0]=histogram[0];
for(int i=1;i<256;i++)
cdf[i]=(cdf[i-1]+histogram[i]);
double max=-999,min=999;
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
/*finding elements of out by function */
out[i*width+j]=pow( ( pow(g_max,0.33) - pow(g_min,0.33) ) * cdf[inbuf[i*width+j]] + pow(g_min,0.33), 3 );
if(out[i*width+j]>max)max=out[i*width+j];
if(out[i*width+j]<min)min=out[i*width+j];
}
}
//double 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