一种简单的图像白平衡计算方法
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>using namespace cv;
using namespace std;enum
{WHITE_BALANCE_SIMPLE = 0,WHITE_BALANCE_GRAYWORLD = 1
};/*白平衡******************************************************************************************************************/
void balanceWhite(std::vector<Mat> &src, Mat &dst, const float inputMin, const float inputMax, const float outputMin, const float outputMax, const int algorithmType)
{// 在rgb三通道上分别计算直方图// 将1%的最大值和最小值设置为255和0// 其余值映射到(0, 255), 这样使得每个值通道的值在rgb中分布较均匀, 以实现简单的颜色平衡switch (algorithmType){case WHITE_BALANCE_SIMPLE:{/********************* Simple white balance *********************/float s1 = 1.0f;// low quantilefloat s2 = 1.0f;// high quantileint depth = 2;// depth of histogram treeint bins = 16;// number of bins at each histogram levelint total = src[0].cols * src[0].rows;int nElements = int(pow((float)bins, (float)depth));// number of elements in histogram treefor (size_t k = 0; k < src.size(); ++k){std::vector<int> hist(nElements, 0);uchar *pImag = src[k].data;// histogram fillingfor (int i = 0; i < total; i++){int pos = 0;float minValue = inputMin - 0.5f;float maxValue = inputMax + 0.5f;float interval = float(maxValue - minValue) / bins;uchar val = pImag[i];for (int j = 0; j < depth; ++j){int currentBin = int((val - minValue + 1e-4f) / interval);++hist[pos + currentBin];pos = (pos + currentBin)*bins;minValue = minValue + currentBin*interval;interval /= bins;}}int p1 = 0, p2 = bins - 1;int n1 = 0, n2 = total;float minValue = inputMin - 0.5f;float maxValue = inputMax + 0.5f;float interval = float(maxValue - minValue) / bins;// searching for s1 and s2for (int j = 0; j < depth; ++j){while (n1 + hist[p1] < s1 * total / 100.0f){n1 += hist[p1++];minValue += interval;}p1 *= bins;while (n2 - hist[p2] > (100.0f - s2) * total / 100.0f){n2 -= hist[p2--];maxValue -= interval;}p2 = p2*bins - 1;interval /= bins;}src[k] = (outputMax - outputMin) * (src[k] - minValue) / (maxValue - minValue) + outputMin;}/****************************************************************/break;}default:CV_Error_(CV_StsNotImplemented, ("Unsupported algorithm type (=%d)", algorithmType));}// switchmerge(src, dst);
}void balanceWhite(const Mat &src, Mat &dst, const int algorithmType, const float inputMin = 0.0f, const float inputMax = 255.0f, const float outputMin = 0.0f, const float outputMax = 255.0f)
{switch (src.depth()){case CV_8U:{std::vector<Mat> mv;split(src, mv);balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType);break;}default:CV_Error_(CV_StsNotImplemented, ("Unsupported source image format (=%d)", src.type()));break;}
}
/**************************************************************************************************************************/int main()
{const char* fileName = "dog.png" ;Mat src = imread(fileName);imshow("src", src);cv::Mat dst(src.size(), src. type());balanceWhite(src, dst, WHITE_BALANCE_SIMPLE);imshow("dst", dst);imwrite("result.jpg", dst);cv::waitKey();return 0;
}
一种简单的图像白平衡计算方法相关推荐
- 四种简单的图像显著性区域特征提取方法-----AC/HC/LC/FT。
四种简单的图像显著性区域特征提取方法-----> AC/HC/LC/FT. 分类: 图像处理 2014-08-03 12:40 4088人阅读 评论(4) 收藏 举报 salient regio ...
- 四种简单的图像显著性区域特征提取方法----- AC/HC/LC/FT。
四种简单的图像显著性区域特征提取方法-----> AC/HC/LC/FT. 分类: 图像处理 2014-08-03 12:40 4088人阅读 评论(4) 收藏 举报 salient regio ...
- 一种简单的图像LDR->HDR算法
算法比较简单,尽量简单说. 文章:Fully-automatic inverse tone mapping algorithm based on dynamic mid-level tone mapp ...
- 鱼眼校正c语言算法,一种简单而精确的鱼眼图像校正算法研究
舒旭 摘 要: 针对鱼眼图像的校正提出了一种有效区域提取算法,并在鱼眼图像的球面物投影平面展开时与目标半立方体的校正平面建立线性映射.实验结果表明,该算法能有效地提取鱼眼图像轮廓的有效区域,同时半立方 ...
- 四种比较简单的图像显著性区域特征提取方法原理及实现
四种比较简单的图像显著性区域特征提取方法原理及实现-----> AC/HC/LC/FT. laviewpbt 2014.8.4 编辑 Email:laviewpbt@sina.com QQ ...
- 一种简单快速有效的图像暗部增强/亮度均衡算法
2020/10/27更新:之前为克服光晕效应尝试过引导滤波,惜哉其他地方犯了个小错误以致未达到目标,处理的结果虽然保边但却过于模糊.后期修正之后再次尝试便得到了预期的效果.现将引入了引导滤波去光晕的程 ...
- Matlab实现图像白平衡(灰度世界法、全反射算法)
参考:https://www.cnblogs.com/molakejin/p/5766132.html 白平衡 白平衡的英文为White Balance,其基本概念是"不管在任何光源下,都能 ...
- 摄像头、视频采集和摄像设备图像质量判断的几种简单有效目测方法
来源:http://blog.csdn.net/lezhiyong 视频图像性能的几种简单目测方法,也可在购买视频采集和摄像设备拿来做参考 软件编解码性能测试: 摄像头前快速挥手,看手部是否连贯.是否 ...
- 基于qml创建最简单的图像处理程序(1)-基于qml创建界面
<基于qml创建最简单的图像处理程序>系列课程及配套代码 基于qml创建最简单的图像处理程序(1)-基于qml创建界面 http://www.cnblogs.com/jsxyhelu/p/ ...
- ICCV2021 Oral SimROD:简单高效的数据增强!华为提出了一种简单的鲁棒目标检测自适应方法...
点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 作者丨小马 来源丨我爱计算机视觉 ▊ 写在前面 本文提出了一种简单有效的鲁棒目标检测无监督自适应方法( ...
最新文章
- python websocket例程_python 实现websocket
- gearman python 实例
- HDU1812 - Count the Tetris
- Python 学习笔记(1)
- MyEclipse 10.5 安装SVN插件
- 一直认为in,exists 不走索引,被同事鄙视了……
- 《1024伐木累》-程序员妹子与花木兰
- 软件机器人从幕后到台前 RPA+Chatbot带来“端到端的自动化”
- jquery 弹出遮罩层
- 环境安装_Python教程 Python环境安装
- mysql学习day02
- MySQL蜜罐在护网中提取攻击者微信ID
- CAS配置数据库进行用户验证
- 程序设计导引及在线实践——练习记录
- python 微信公众号发文章_Python 微信公众号文章爬取
- 【数据分析|面试】如何介绍你的项目经历
- 计算机函数求奖学金,Excel函数在高校奖学金评定中的实践应用参考.pdf
- java 实现 指派_Activiti 开发案例之动态指派任务
- t00lsudf.php,udf提权
- [转] 公共DNS,114.114.114.114和8.8.8.8
热门文章
- 《金狐系统维护盘》五周年纪念版【简洁易用,强大实用】
- 【翻译】图解Janusgraph系列-事务详解(Janusgraph Transactions)
- 关于http响应200 OK的问题
- 开源的视频编解码器介绍
- 计算机图形学:中点划线法(任意斜率)
- OV426+OVM6946基于FPGA调试成像
- android 距离感应器控制屏幕熄灭_华为nova3e、小米6X、OPPOA7x对比,选IPS屏幕还是TFT屏幕,自选...
- ARM架构(RISC)和x86架构(CISC)以及传统与移动CPU/GPU厂商
- 2017年下半年网络工程师真题+答案解析
- 不属于微型计算机的技术特标,计算机组成原理汇总