C# OpenCvSharp利用白平衡技術(shù)實(shí)現(xiàn)圖像修復(fù)功能
C# OpenCvSharp 利用白平衡技術(shù)進(jìn)行圖像修復(fù)
OpenCV xphoto模塊中提供了三種不同的白平衡算法,分別是:灰度世界(GrayworldWB)算法、完完美反射(SimpleWB)算法和基于學(xué)習(xí)的(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
基于學(xué)習(xí)的(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_利用白平衡技術(shù)進(jìn)行圖像修復(fù) { 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> /// 基于學(xué)習(xí)的(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()); } } }
到此這篇關(guān)于C# OpenCvSharp利用白平衡技術(shù)實(shí)現(xiàn)圖像修復(fù)功能的文章就介紹到這了,更多相關(guān)C# OpenCvSharp圖像修復(fù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#中StringBuilder用法以及和String的區(qū)別分析
當(dāng)我們?cè)诔鯇W(xué)使用C#時(shí),常常會(huì)不知道該用StringBuilder合適還是用String高效,下面是我在學(xué)習(xí)當(dāng)中對(duì)StringBuilder和String的區(qū)別總結(jié),分享給大家。2013-03-03C#根據(jù)IP地址查詢所屬地區(qū)實(shí)例詳解
這篇文章主要介紹了C#根據(jù)IP地址查詢所屬地區(qū)實(shí)例詳解,調(diào)用的接口是免費(fèi)的接口,有需要的同學(xué)可以研究下2021-03-03C#實(shí)現(xiàn)PDF合并的項(xiàng)目實(shí)踐
有時(shí)我們可能會(huì)遇到需要的資料或教程被分成了幾部分存放在多個(gè)PDF文件中,本文主要介紹了C#實(shí)現(xiàn)PDF合并的項(xiàng)目實(shí)踐,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01C# Winform截圖指定控件范圍內(nèi)的圖像的流程步驟
工作所需,需要截圖軟件跑出來的界面上的圖表,但是窗口本身是可以縮放的,圖表也是做的可以跟著窗體大小一起縮放,所以就寫了一個(gè)函數(shù),用于截圖圖表容器內(nèi)的圖像,文中有函數(shù)源碼供大家參考,需要的朋友可以參考下2024-10-10使用C#實(shí)現(xiàn)一個(gè)簡單的繪圖工具
這篇文章主要為大家詳細(xì)介紹了如何使用C#開發(fā)的簡單繪圖工具,可以將簽名簡單繪圖后的效果以圖片的形式導(dǎo)出,有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02將數(shù)組中指定數(shù)量的元素移動(dòng)數(shù)組后面的實(shí)現(xiàn)代碼
本篇文章是對(duì)將數(shù)組中指定數(shù)量的元素移動(dòng)數(shù)組后面的實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06C#實(shí)現(xiàn)創(chuàng)建,刪除,查找,配置虛擬目錄實(shí)例詳解
這篇文章主要介紹了C#創(chuàng)建,刪除,查找,配置虛擬目錄的方法,以實(shí)例形式較為詳細(xì)的分析了C#針對(duì)虛擬目錄的創(chuàng)建、刪除、查找等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08