0

I have to implement a gamma correction code for Image processing course.

for(k=0;k<255;k++){g[k]=255*pow((double)k/255,1/gamma);}

Now i will get a black picture no matter what gamma i choose. The rest of the processing code is given by the tutor so the mistake have to be here.

Grunwalski
  • 129
  • 5
  • No background info so we can just guess: `g[]` is the color palette? `q[k]` is in what range (`<0,255>`?) and what data type(int/float)? The gamma correction looks OK if g[k] is in range <0,255> so either you have float/int rounding error somewhere (`255*pow` and `(double)k/255` and `1/gamma` looks suspicious) try `255.0*pow` or `double(k)/255.0`,... or you forget to recolor the image properly try `g[k]=k` (original image), `g[k]=255-k` (inverted image) to check the recoloring. What language,platform is this for? – Spektre Jun 11 '15 at 11:46
  • what is the value of `gamma` (hope not `0`)? look here [Impact of cubic and catmull splines on image](http://stackoverflow.com/q/23614037/2521214) for some additional ideas – Spektre Jun 11 '15 at 11:50
  • Oh sorry for the information lack. The range of grey values are between 0 and 255. For every grey value k , its is mapped to a new value g[k]. Then g[k] is applied to the image : for (i=1; i<=nx; i++) for (j=1; j<=ny; j++) u[i][j] = g[(long)(u[i][j])] This is written in C. I tried your proposals, but it didnt work out. – Grunwalski Jun 11 '15 at 12:05
  • define did not work? what happens if you set `for (k=0;k<256;k++) g[k]=255-k;` ? if the image is still black then the problem is in the recoloring if the output is inverted image then the problem is in the gamma. btw do you have loaded image (non black before recolor)? – Spektre Jun 11 '15 at 12:28
  • Thank you alot. Apparently my mistake is trivial, i forgot to set ending brackets( i set it in the question but forgot it in the editor ) . Sorry for wasting your time – Grunwalski Jun 11 '15 at 12:51

0 Answers0