Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The principle of perfect reflection algorithm of automatic White balance and what is the implementation of C++?

2025-02-21 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 the perfect reflection algorithm of automatic white balance and the implementation of C++. The content is very detailed. Interested friends can use it for reference. I hope it can be helpful to you.

Preface

The grayscale world algorithm introduced yesterday is the most primitive algorithm for dealing with white balance. The perfect reflection algorithm introduced today is also one of the commonly used algorithms for automatic white balance. Let's take a look.

Algorithm principle

The perfect reflection theory assumes that the brightest point in the image is the white point, and uses this white point as a reference for automatic white balance of the image, and the brightest point is defined as the maximum value of R+G+B.

Algorithm process

After calculating each pixel R _ Magi _ B, and save

Calculate the threshold T of the white reference point of the top 10% or other Ratio according to the value of R+G+B

Traverses each point in the image and calculates the average of the cumulative sum of R\ G\ B components of all points where the value of Randy G + B is greater than T

Quantize each pixel to [0,255]

Code implementation

Mat PerfectReflectionAlgorithm (Mat src) {int row = src.rows; int col = src.cols; Mat dst (row, col, CV_8UC3); int HistRGB = {0}; int MaxVal = 0; for (int I = 0; I

< row; i++) { for (int j = 0; j < col; j++) { MaxVal = max(MaxVal, (int)src.at(i, j)[0]); MaxVal = max(MaxVal, (int)src.at(i, j)[1]); MaxVal = max(MaxVal, (int)src.at(i, j)[2]); int sum = src.at(i, j)[0] + src.at(i, j)[1] + src.at(i, j)[2]; HistRGB[sum]++; } } int Threshold = 0; int sum = 0; for (int i = 766; i >

= 0; iMel -) {sum + = HistRGB [I]; if (sum > row * col * 0.1) {Threshold = I; break;}} int AvgB = 0; int AvgG = 0; int AvgR = 0; int cnt = 0; for (int I = 0; I

< row; i++) { for (int j = 0; j < col; j++) { int sumP = src.at(i, j)[0] + src.at(i, j)[1] + src.at(i, j)[2]; if (sumP >

Threshold) {AvgB + = src.at (I, j) [0]; AvgG + = src.at (I, j) [1]; AvgR + = src.at (I, j) [2]; cnt++;}} AvgB / = cnt; AvgG / = cnt; AvgR / = cnt; for (int I = 0; I

< row; i++) { for (int j = 0; j < col; j++) { int Blue = src.at(i, j)[0] * MaxVal / AvgB; int Green = src.at(i, j)[1] * MaxVal / AvgG; int Red = src.at(i, j)[2] * MaxVal / AvgR; if (Red >

{Red = 255;} else if (Red

< 0) { Red = 0; } if (Green >

{Green = 255;} else if (Green

< 0) { Green = 0; } if (Blue >

{Blue = 255;} else if (Blue < 0) {Blue = 0;} dst.at (I, j) [0] = Blue; dst.at (I, j) [1] = Green; dst.at (I, j) [2] = Red;}} return dst;}

Effect.

On the automatic white balance of the perfect reflection algorithm principle and C++ implementation is shared here, I hope the above content can be of some help to you, can 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report