In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the principle of grayscale world algorithm and the example analysis of C++ implementation, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.
Pre-content
The human visual system has color constancy, which can obtain the invariant characteristics of the surface color of the object from the changing lighting environment and imaging conditions, but the imaging equipment does not have such an adjustment function. Different lighting environments will lead to a certain degree of deviation between the captured image color and the real color, so it is necessary to choose an appropriate color balance algorithm to eliminate the influence of lighting environment on color display.
Principle of grayscale world algorithm
The grayscale world algorithm is based on the grayscale world hypothesis, which assumes that for an image with a large number of color changes, the average value of RGB3 components tends to the same gray value Gray. In the physical sense, the grayscale world algorithm assumes that the average reflection of natural scenery to light is a fixed value as a whole, which is approximately "gray". The color balance algorithm forces this assumption to be applied to the image to be processed, which can eliminate the influence of ambient light from the image and obtain the original scene image.
Algorithm step
Advantages and disadvantages of algorithm
This algorithm is simple and fast, but when the color of the image scene is not rich, especially when there are a large number of monochromatic objects, the algorithm will fail.
Source code implementation
Mat GrayWorld (Mat src) {vector bgr; cv::split (src, bgr); double B = 0; double G = 0; double R = 0; int row = src.rows; int col = src.cols; Mat dst (row, col, CV_8UC3); for (int I = 0; I
< row; i++) { for (int j = 0; j < col; j++) { B += 1.0 * src.at(i, j)[0]; G += 1.0 * src.at(i, j)[1]; R += 1.0 * src.at(i, j)[2]; } } B /= (row * col); G /= (row * col); R /= (row * col); printf("%.5f %.5f %.5f\n", B, G, R); double GrayValue = (B + G + R) / 3; printf("%.5f\n", GrayValue); double kr = GrayValue / R; double kg = GrayValue / G; double kb = GrayValue / B; printf("%.5f %.5f %.5f\n", kb, kg, kr); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { dst.at(i, j)[0] = (int)(kb * src.at(i, j)[0]) >(int) (kb * src.at (I, j) [0]); dst.at (I, j) [1] = (int) (kg * src.at (I, j) [1]) > 255255: (int) (kg * src.at (I, j) [1]) Dst.at (I, j) [2] = (int) (kr * src.at (I, j) [2]) > 255255: (int) (kr * src.at (I, j) [2]);}} return dst;}
Effect picture
Conclusion
We can see that the grayscale world algorithm has the effect of white balance, and the execution speed of the algorithm is very fast.
This is the end of the example analysis on the principle of the grayscale world algorithm and the implementation of C++. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.