gamma correction in opencv java [closed]
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.
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 ...)