views:

60

answers:

3

Hey guys and gals,

So I load a color .png file that has been taken with an iphone using cvLoadImage. And after it's been loaded, when I immediately display it in my X11 terminal, the image is definitely darker than the original png file.

I currently use this to load the image: IplImage *img3 = cvLoadImage( "bright.png", 1);

For the second parameter I have tried all of the following:

CV_LOAD_IMAGE_UNCHANGED

CV_LOAD_IMAGE_GRAYSCALE

CV_LOAD_IMAGE_COLOR

CV_LOAD_IMAGE_ANYDEPTH

CV_LOAD_IMAGE_ANYCOLOR

but none of these have worked. Grayscale definitely made the image grayscale. But as suggested from http://www.cognotics.com/opencv/docs/1.0/ref/opencvref_highgui.htm, even using CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR to load the image as truthfully as possible resulted in a darker image being displayed in the terminal.

Does anyone have any ideas on how to get the original image to display properly?

Thanks a lot in advance.

+1  A: 

It only happens when you load it in OpenCV? Opening with any other viewer doesn't show a difference?

I can't confirm this without a few tests but I believe the iPhone display gamma is 1.8 (source: http://www.colorwiki.com/wiki/Color_on_iPhone#The_iPhone.27s_Display). Your X11 monitor probably is adjusted for 2.2 (like the rest of the world).

If this theory holds, yes, images are going to appear darker on X11 than on the iPhone. You may change your monitor calibration or do some image processing to account for the difference.

Edit:

I believe OpenCV really does not apply gamma correction. My reference to this is here:

http://permalink.gmane.org/gmane.comp.lib.opencv.devel/837

You might want to implement it yourself or "correct" it with ImageMagick. This page instructs you on how to do so:

http://www.4p8.com/eric.brasseur/gamma.html

Vitor Py
When I opened it in Preview and Adobe Photoshop on the same mac laptop, the image displays as it appears on my iphone. Only through the X11 terminal does it appear darker. My problem is that when I go to retrieve the pixel RGB values of my image, I'm returned the darker images RGB values as opposed to what they should be from my original image (I verified this by using the color utility tool on the mac). Do you have any idea on how to get the pixel RGB values for the original (lighter) image? Thanks a lot for your response.
You want to apply gamma correction to your OpenCV images. You may do this using ImageMagick or implement it yourself. I'll edit my post with some references.
Vitor Py
A: 

I usually load an image with:

cvLoadImage("file.png", CV_LOAD_IMAGE_UNCHANGED);

One interesting test you could do to detect if OpenCV is really messing with the image data, is simply creating another image with cvCreateImage(), then copy the data to this newly created image and save it to another file with cvLoadImage().

Maybe, it's just a display error. Of course, I would suggest you to update to the most recent version of OpenCV.

karlphillip
+1  A: 

Yes, OpenCV does not apply Gamma correction.


// from: http://gegl.org/
// value: 0.0-1.0
static inline qreal
linear_to_gamma_2_2 (qreal value){
  if (value > 0.0030402477)
    return 1.055 * pow (value, (1.0/2.4)) - 0.055;
  return 12.92 * value;
}
// from: http://gegl.org/
static inline qreal
gamma_2_2_to_linear (qreal value){
  if (value > 0.03928)
    return pow ((value + 0.055) / 1.055, 2.4);
  return value / 12.92;
}

Ross