Gamma correction principle

Source: Internet
Author: User
Tags comparison table

http://blog.csdn.net/u013286409/article/details/50239377

Directory (?) [-]

Figure2 after correction , lower contrast on the left > Clearly you can see the face

On the right, gamma = 2.2 is corrected, the contrast on the left is increased ( see Beard ), theright side is lowered in contrast (the face is more unclear ), and theoverall grayscale value of the image decreases.

It is worth mentioning that the human eye is processed according to the Gamma < 1 curve of the input image.

[CPP]View Plaincopy print?
  1. #include <opencv2/core/core.hpp>
  2. #include <opencv2/imgproc/imgproc.hpp>
  3. #include <opencv2/highgui/highgui.hpp>
  4. #include <iostream>
  5. Using namespace CV;
  6. Using namespace std;
  7. Normalizes a given image into a value range between 0 and 255.
  8. Mat norm_0_255 (const mat& src) {
  9. //Create and return normalized image:
  10. Mat DST;
  11. switch (src.channels ()) {
  12. Case 1:
  13. Cv::normalize (SRC, DST, 0, 255, Norm_minmax, CV_8UC1);
  14. Break ;
  15. Case 3:
  16. Cv::normalize (SRC, DST, 0, 255, Norm_minmax, CV_8UC3);
  17. Break ;
  18. Default:
  19. Src.copyto (DST);
  20. Break ;
  21. }
  22. return DST;
  23. }
  24. int main (int argc, const Char *argv[]) {
  25. //Get filename to the source image:
  26. if (argc! = 2) {
  27. cout << "usage:" << argv[0] << "<image.ext>" << Endl;
  28. Exit (1);
  29. }
  30. //Load image & get skin proportions:
  31. //mat image = Imread (argv[1], cv_load_image_grayscale);
  32. Mat image = Imread (argv[1], cv_load_image_color);
  33. //Convert to floating point:
  34. Mat X;
  35. Image.convertto (X, CV_32FC1);
  36. //image.convertto (X, cv_32f);
  37. //Start preprocessing:
  38. Mat I;
  39. float gamma = 1/2.2;
  40. Pow (X, Gamma, I);
  41. //Draw It on screen:
  42. Imshow ("Original image", image);
  43. Imshow ("Gamma correction image", norm_0_255 (I));
  44. //imwrite ("origin.jpg", image);
  45. Imwrite ("Gamma_inv2.2.jpg", norm_0_255 (I));
  46. //Show the images:
  47. Waitkey (0);
  48. //success!
  49. return 0;
  50. }
#include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/ Highgui.hpp> #include <iostream> using namespace cv;using namespace std;//normalizes a given image into a value    Range between 0 and 255.Mat norm_0_255 (const mat& src) {//Create and return normalized image:mat DST;        Switch (Src.channels ()) {case 1:cv::normalize (src, DST, 0, 255, Norm_minmax, CV_8UC1);    Break        Case 3:cv::normalize (SRC, DST, 0, 255, Norm_minmax, CV_8UC3);    Break        Default:src.copyTo (DST);    Break } return DST;} int main (int argc, const char *argv[]) {//Get filename to the source image:if (argc! = 2) {cout <<        "Usage:" << argv[0] << "<image.ext>" << Endl;    Exit (1); }//Load image & get skin proportions://mat image = Imread (argv[1], cv_load_image_grayscale);    Mat image = Imread (argv[1], cv_load_image_color); ConverT to floating Point:mat X;image.convertto (x, CV_32FC1);//image.convertto (x, cv_32f);    Start preprocessing:mat i;float gamma = 1/2.2;    Pow (X, Gamma, I);    Draw it on screen:imshow ("Original image", image); Imshow ("Gamma correction image", norm_0_255 (I)),//imwrite ("origin.jpg", image); Imwrite ("Gamma_inv2.2.jpg", norm_0_    255 (I));    Show the Images:waitkey (0);    success! return 0;}

Gamma correction

Question: What is gamma curve correction? What does gamma curve correction mean?
Gamma curve is a special tone curve, when the gamma value equals 1, the curve is a straight line with the axis 45°, this time indicates the same input and output density. A gamma value above 1 will cause the output to illuminate, and a gamma value below 1 will cause the output to darken. In short, our requirement is that the input and output ratios be as close to 1 as possible. This is a fairly common and more important concept in input and output devices such as displays, scanners, and printers. In the computer system, due to the graphics card or the display of the actual output of the image in the brightness of the deviation, and gamma curve correction is a certain way to correct this deviation of the image method. In general, when the value for gamma correction is greater than 1 o'clock, the highlight portion of the image is compressed and the darkened portion is expanded, and when the gamma correction value is less than 1 o'clock, the highlight portion of the image is expanded and the darkened portion is compressed, and gamma correction is generally used to smooth the details of the extended dimming.

Figure 1 The luminance response curve of a CRT display

Figure 1 shows the general CRT display Brightness response curve, you can see its input voltage increase by one times, the brightness output is not increased by one times, but close to twice times, it is obvious that the output of the image with the original image is the output of the phenomenon of light, That is, a CRT monitor that is not gamma-corrected has a gamma value of less than 1.

A device that has no gamma correction affects the color brightness of the final output image, such as a color consisting of red and green, a red brightness of 50%, and a green brightness of 25%. If the gamma value of a CRT monitor that has not been corrected by Gamma is 2.5, the output brightness will be 18% and 3% respectively, and its brightness is greatly reduced.

Figure 2 curve compensation by graph

In order to compensate for this shortcoming, we need to use the inverse effect compensation curve to let the monitor output the same image as the input image as possible, so the input signal of the monitor should be compensated according to the curve shown in Figure 2, so that the output of the display can be more satisfactory.

Figure 3 curve in an ideal state

The general inverse effect can be directly assigned to the image stored in the frame cache, so that the gamma curve is non-linear, but also through the ramdac of the inverse effect compensation (or gamma curve correction). This allows us to see the image close to the image we entered on the display (3). Of course, the curve shown in Figure 3 is only in the ideal state of the situation, in practical applications we can not get such a perfect curve, so the competition between the different manufacturers is who can achieve the closest to this effect.

The gamma value of the display is the mathematical method used to define the display characteristics of a display, and is the value that determines the display from black to white. Simply put, when displaying a color from black to white (that is, 0 to 1), the voltage of the display changes, but this change is not linear. Because the physical characteristics of the display determine if the voltage changes are linear, the displayed brightness is not linear, then the brightness of the display will be very dark. Therefore, in order to ensure that the brightness of the display is normal (linear), you need to adjust the voltage change of the monitor, this value is what we commonly say gamma value. This is usually done only when you are adjusting the Hdri picture and when animating the rendering.

Gamma correction (gamma Correction, gamma correction): the so-called gamma correction is to edit the image gamma curve, in order to the image of non-linear tone editing method, detect the image signal in the dark and light parts, and increase the proportion of the two, thereby improving the image contrast effect. In the field of computer graphics, the conversion relationship between the output voltage of this screen and the corresponding luminance is referred to as the Gamma curve (Gamma Curve). In the traditional CRT (cathode Ray Tube) screen characteristics, the curve is usually a power function, y= (x+e) γ, wherein Y is brightness, X is the output voltage, E is the compensation factor, the Power value (gamma) is the gamma value, change the power value (gamma) size, you can change the CRT gamma curve. A typical gamma value is 0.45, which causes the CRT's image brightness to appear linearly. The display screen, such as the CRT's TV, is not linear but an exponential function because of the luminous grayscale of the input signal, so it must be corrected.

In the TV and graphics monitor, the electron beam and the image brightness generated by the picture tube are not linearly changed with the input voltage of the kinescope, and the electron flow is changed according to the exponential curve compared with the input voltage, and the input voltage index is larger than that of the electron beam. This indicates that the dark area signals are darker than the actual situation, and the light area is higher than the actual situation. So, to reproduce the footage taken by the camera, the TV and monitor must be compensated for gamma. This gamma correction can also be done by the camera. The purpose of gamma compensation for the entire television system is to make the camera output signal based on the symmetry of the incident light and the luminance of the picture tube, so the image signal should be introduced to an inverse nonlinear distortion, that is, the camera gamma curve corresponding to the gamma curve of the TV system, the value of which should be 1/γ, We call the gamma value of the camera. The gamma value of the TV system is about 2.2, so the camera nonlinearity of the TV system compensates for the gamma value of 0.45. The gamma value of the color picture tube is 2.8, its image signal correction index should be 1/2.8=0.35, but because of the effect of stray light inside and outside the picture tube, reproduce the image contrast and saturation have been reduced, so now the color camera gamma value still more than 0.45. In the practical application, we can adjust the gamma value in a certain range according to the actual situation, in order to obtain the best result.

Today, a friend asked about the usefulness of gamma correction, here is a brief:

Gamma correction was originally caused by the imaging distortion of the cathode phenomenon tube of the display (i.e., the cathode rays version of the oscilloscope tubes), in order to not distort the picture, it was corrected by a special algorithm, which is called gamma correction.

The principle of gamma correction is to modify the display system color scheme, originally showed the system output R G B Electron gun linearly according to each color value in the memory output corresponding control voltage, but through the gamma correction can be a color value corresponding to the output voltage adjustment high or low adjustment. Achieve the purpose of correcting the color of the display system. At the same time can be corrected by the software method, that is, a picture set a color color value into a new color value of the comparison table, and then replace the original image with the new color value of the corresponding color on the line AH. For example, you first write a control of the RGB component corresponding to the curve adjuster, adjust the control curve in the curve adjuster to set the original color how much corresponding to the target color, and then according to the relationship, modify the color of the picture to adjust the colors of each pixel can be.

The mathematical formula can grasp a concept profoundly and precisely, but it can't express the physical meaning and the essential meaning of the concept, this paste tries to get rid of the statement and derivation of the mathematical formula, and explain the essential meaning of gamma with the words.

Original link:

http://blog.csdn.net/lichengyu/article/details/20840135

Http://www.downhot.com/show/dnjc/160420120603552393894.html

Gamma correction principle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.