Ask Your Question

Revision history [back]

gamma correction in opencv java

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.