C# OpenCvSharp 利用白平衡技术进行图像修复

2024-02-24 06:28

本文主要是介绍C# OpenCvSharp 利用白平衡技术进行图像修复,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

效果

灰度世界(GrayworldWB)-白平衡算法

完美反射(SimpleWB)-白平衡算法

基于学习的(LearningBasedWB)-白平衡算法

代码

下载


C# OpenCvSharp 利用白平衡技术进行图像修复

OpenCV xphoto模块中提供了三种不同的白平衡算法,分别是:灰度世界(GrayworldWB)算法、完完美反射(SimpleWB)算法和基于学习的(LearningBasedWB)白平衡算法

效果

灰度世界(GrayworldWB)-白平衡算法

参考链接:https://docs.opencv.org/4.x/d7/d71/classcv_1_1xphoto_1_1GrayworldWB.html#details

完美反射(SimpleWB)-白平衡算法

参考链接:https://docs.opencv.org/4.x/d1/d8b/classcv_1_1xphoto_1_1SimpleWB.html#details

基于学习的(LearningBasedWB)-白平衡算法

参考链接:https://docs.opencv.org/4.x/dc/dcb/tutorial_xphoto_training_white_balance.html

代码

using OpenCvSharp;
using OpenCvSharp.XPhoto;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace C__OpenCvSharp_利用白平衡技术进行图像修复
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        Mat image;
        Mat dst = new Mat();
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            pictureBox1.Image = null;
            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            image = new Mat(image_path);
            pictureBox2.Image = null;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            image_path = "1.jpg";
            pictureBox1.Image = new Bitmap(image_path);
        }

        /// <summary>
        /// 灰度世界(GrayworldWB)-白平衡算法
        /// https://docs.opencv.org/4.x/d7/d71/classcv_1_1xphoto_1_1GrayworldWB.html#details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            pictureBox2.Image = null;

            image = new Mat(image_path);
            WhiteBalancer wb = CvXPhoto.CreateGrayworldWB();
            wb.BalanceWhite(image, dst);
            pictureBox2.Image = new Bitmap(dst.ToMemoryStream());
        }

        /// <summary>
        /// 完美反射(SimpleWB)-白平衡算法
        /// https://docs.opencv.org/4.x/d1/d8b/classcv_1_1xphoto_1_1SimpleWB.html#details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            pictureBox2.Image = null;

            image = new Mat(image_path);
            WhiteBalancer wb = CvXPhoto.CreateSimpleWB();
            wb.BalanceWhite(image, dst);
            pictureBox2.Image = new Bitmap(dst.ToMemoryStream());
        }

        /// <summary>
        /// 基于学习的(LearningBasedWB)-白平衡算法
        /// https://docs.opencv.org/4.x/dc/dcb/tutorial_xphoto_training_white_balance.html
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            pictureBox2.Image = null;

            image = new Mat(image_path);
            string model = "";//模型路径
            WhiteBalancer wb = CvXPhoto.CreateLearningBasedWB(model);
            wb.BalanceWhite(image, dst);
            pictureBox2.Image = new Bitmap(dst.ToMemoryStream());
        }
    }
}

using OpenCvSharp;
using OpenCvSharp.XPhoto;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace C__OpenCvSharp_利用白平衡技术进行图像修复
{public partial class Form1 : Form{public Form1(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";Mat image;Mat dst = new Mat();private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);image = new Mat(image_path);pictureBox2.Image = null;}private void Form1_Load(object sender, EventArgs e){image_path = "1.jpg";pictureBox1.Image = new Bitmap(image_path);}/// <summary>/// 灰度世界(GrayworldWB)-白平衡算法/// https://docs.opencv.org/4.x/d7/d71/classcv_1_1xphoto_1_1GrayworldWB.html#details/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){if (image_path == ""){return;}pictureBox2.Image = null;image = new Mat(image_path);WhiteBalancer wb = CvXPhoto.CreateGrayworldWB();wb.BalanceWhite(image, dst);pictureBox2.Image = new Bitmap(dst.ToMemoryStream());}/// <summary>/// 完美反射(SimpleWB)-白平衡算法/// https://docs.opencv.org/4.x/d1/d8b/classcv_1_1xphoto_1_1SimpleWB.html#details/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button3_Click(object sender, EventArgs e){if (image_path == ""){return;}pictureBox2.Image = null;image = new Mat(image_path);WhiteBalancer wb = CvXPhoto.CreateSimpleWB();wb.BalanceWhite(image, dst);pictureBox2.Image = new Bitmap(dst.ToMemoryStream());}/// <summary>/// 基于学习的(LearningBasedWB)-白平衡算法/// https://docs.opencv.org/4.x/dc/dcb/tutorial_xphoto_training_white_balance.html/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button4_Click(object sender, EventArgs e){if (image_path == ""){return;}pictureBox2.Image = null;image = new Mat(image_path);string model = "";//模型路径WhiteBalancer wb = CvXPhoto.CreateLearningBasedWB(model);wb.BalanceWhite(image, dst);pictureBox2.Image = new Bitmap(dst.ToMemoryStream());}}
}

下载

源码下载

这篇关于C# OpenCvSharp 利用白平衡技术进行图像修复的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/741219

相关文章

基于人工智能的图像分类系统

目录 引言项目背景环境准备 硬件要求软件安装与配置系统设计 系统架构关键技术代码示例 数据预处理模型训练模型预测应用场景结论 1. 引言 图像分类是计算机视觉中的一个重要任务,目标是自动识别图像中的对象类别。通过卷积神经网络(CNN)等深度学习技术,我们可以构建高效的图像分类系统,广泛应用于自动驾驶、医疗影像诊断、监控分析等领域。本文将介绍如何构建一个基于人工智能的图像分类系统,包括环境

2. c#从不同cs的文件调用函数

1.文件目录如下: 2. Program.cs文件的主函数如下 using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;namespace datasAnalysis{internal static

【专题】2024飞行汽车技术全景报告合集PDF分享(附原数据表)

原文链接: https://tecdat.cn/?p=37628 6月16日,小鹏汇天旅航者X2在北京大兴国际机场临空经济区完成首飞,这也是小鹏汇天的产品在京津冀地区进行的首次飞行。小鹏汇天方面还表示,公司准备量产,并计划今年四季度开启预售小鹏汇天分体式飞行汽车,探索分体式飞行汽车城际通勤。阅读原文,获取专题报告合集全文,解锁文末271份飞行汽车相关行业研究报告。 据悉,业内人士对飞行汽车行业

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

业务中14个需要进行A/B测试的时刻[信息图]

在本指南中,我们将全面了解有关 A/B测试 的所有内容。 我们将介绍不同类型的A/B测试,如何有效地规划和启动测试,如何评估测试是否成功,您应该关注哪些指标,多年来我们发现的常见错误等等。 什么是A/B测试? A/B测试(有时称为“分割测试”)是一种实验类型,其中您创建两种或多种内容变体——如登录页面、电子邮件或广告——并将它们显示给不同的受众群体,以查看哪一种效果最好。 本质上,A/B测

金融业开源技术 术语

金融业开源技术  术语 1  范围 本文件界定了金融业开源技术的常用术语。 本文件适用于金融业中涉及开源技术的相关标准及规范性文件制定和信息沟通等活动。

用命令行的方式启动.netcore webapi

用命令行的方式启动.netcore web项目 进入指定的项目文件夹,比如我发布后的代码放在下面文件夹中 在此地址栏中输入“cmd”,打开命令提示符,进入到发布代码目录 命令行启动.netcore项目的命令为:  dotnet 项目启动文件.dll --urls="http://*:对外端口" --ip="本机ip" --port=项目内部端口 例: dotnet Imagine.M

基于51单片机的自动转向修复系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订阅👇🏻 单片机

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出 在数字化时代,文本到语音(Text-to-Speech, TTS)技术已成为人机交互的关键桥梁,无论是为视障人士提供辅助阅读,还是为智能助手注入声音的灵魂,TTS 技术都扮演着至关重要的角色。从最初的拼接式方法到参数化技术,再到现今的深度学习解决方案,TTS 技术经历了一段长足的进步。这篇文章将带您穿越时