gamma correction in opencv java [closed]

asked 2016-11-26 00:35:36 -0600

Mimi gravatar image

Hi, how to translate this not opencv java code to opencv java: for(int i=0; i<img.getwidth(); i++){<="" p="">

for(int j=0; j<img.getHeight(); j++){

   int pixel[] = img.getRaster().getPixel(i, j, new int[3]);
   //get the gamma corrected value
   int k = (int) (255*(Math.pow((double)pixel[0]/(double)255, 2.2)));

   Color color = new Color(k, k, k);

   int rgb = color.getRGB();

   img.setRGB(i, j, rgb);

}

}

I just manage to do this: double inverse_gamma = 1.0 / gamma;

                    for( int i = 0; i < 256; i++ ){
                    imgSource.convertTo(imgDestination, (int)(Math.pow((double) i / 255.0, inverse_gamma ) * 255.0 ));
                    }

but still the program cannot run this.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-17 14:13:17.618290

Comments

can you try to be more explicit about, what you're trying to achieve ?

do you want to correct a single channel, grayscale image ?

(above code looks murky wrt channels)

(also, your own idea obviously does not work - converting the same src img to the same dst image 256 times ...)

berak gravatar imageberak ( 2016-11-26 09:37:04 -0600 )edit