好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁(yè) > 知識(shí)庫(kù) > OpenCV 圖像對(duì)比度的實(shí)踐

OpenCV 圖像對(duì)比度的實(shí)踐

熱門標(biāo)簽:哈爾濱外呼系統(tǒng)代理商 徐州天音防封電銷卡 佛山防封外呼系統(tǒng)收費(fèi) 湛江電銷防封卡 鄭州智能外呼系統(tǒng)運(yùn)營(yíng)商 電話機(jī)器人適用業(yè)務(wù) 南昌辦理400電話怎么安裝 不錯(cuò)的400電話辦理 獲客智能電銷機(jī)器人

本文主要介紹了OpenCV 圖像對(duì)比度,具有一定的參考價(jià)值,感興趣的可以了解一下

實(shí)現(xiàn)原理

圖像對(duì)比度指的是一幅圖像中明暗區(qū)域最亮的白和最暗的黑之間不同亮度層級(jí)的測(cè)量,即指一幅圖像灰度反差的大小。差異范圍越大代表對(duì)比越大,差異范圍越小代表對(duì)比越小。設(shè)置一個(gè)基準(zhǔn)值thresh,當(dāng)percent大于0時(shí),需要令圖像中的顏色對(duì)比更強(qiáng)烈,即數(shù)值距離thresh越遠(yuǎn),則變化越大;當(dāng)percent等于1時(shí),對(duì)比強(qiáng)到極致,只有255和0的區(qū)分;當(dāng)percent等于0時(shí),不變;當(dāng)percent小于0時(shí),對(duì)比下降,即令遠(yuǎn)離thresh的數(shù)值更近些;當(dāng)percent等于-1時(shí),沒(méi)有對(duì)比了,全是thresh值。

對(duì)比度調(diào)整算法的實(shí)現(xiàn)流程如下:

1.設(shè)置調(diào)整參數(shù)percent,取值為-100到100,類似PS中設(shè)置,歸一化后為-1到1。

2.針對(duì)圖像所有像素點(diǎn)單個(gè)處理。當(dāng)percent大于等于0時(shí),對(duì)比增強(qiáng),調(diào)整后的RGB三通道數(shù)值為:

3.若percent小于0時(shí),對(duì)比降低,此時(shí)調(diào)整后的圖像RGB三通道值為:

4.若percent等于1時(shí),大于thresh則等于255,小于則等于0。

至此,圖像實(shí)現(xiàn)了明度的調(diào)整,算法邏輯參考xingyanxiao。C++實(shí)現(xiàn)代碼如下。

功能函數(shù)代碼

// 對(duì)比度
cv::Mat Contrast(cv::Mat src, int percent)
{
	float alpha = percent / 100.f;
	alpha = max(-1.f, min(1.f, alpha));
	cv::Mat temp = src.clone();
	int row = src.rows;
	int col = src.cols;
	int thresh = 127;
	for (int i = 0; i  row; ++i)
	{
		uchar *t = temp.ptruchar>(i);
		uchar *s = src.ptruchar>(i);
		for (int j = 0; j  col; ++j)
		{
			uchar b = s[3 * j];
			uchar g = s[3 * j + 1];
			uchar r = s[3 * j + 2];
			int newb, newg, newr;
			if (alpha == 1)
			{
				t[3 * j + 2] = r > thresh ? 255 : 0;
				t[3 * j + 1] = g > thresh ? 255 : 0;
				t[3 * j] = b > thresh ? 255 : 0;
				continue;
			}
			else if (alpha >= 0)
			{
				newr = static_castint>(thresh + (r - thresh) / (1 - alpha));
				newg = static_castint>(thresh + (g - thresh) / (1 - alpha));
				newb = static_castint>(thresh + (b - thresh) / (1 - alpha));
			}
			else {
				newr = static_castint>(thresh + (r - thresh) * (1 + alpha));
				newg = static_castint>(thresh + (g - thresh) * (1 + alpha));
				newb = static_castint>(thresh + (b - thresh) * (1 + alpha));
 
			}
			newr = max(0, min(255, newr));
			newg = max(0, min(255, newg));
			newb = max(0, min(255, newb));
			t[3 * j + 2] = static_castuchar>(newr);
			t[3 * j + 1] = static_castuchar>(newg);
			t[3 * j] = static_castuchar>(newb);
		}
	}
	return temp;
}

C++測(cè)試代碼

#include opencv2/opencv.hpp>
#include iostream>
using namespace cv;
using namespace std;
 
cv::Mat Contrast(cv::Mat src, int percent);
 
int main()
{
	cv::Mat src = imread("5.jpg");
	cv::Mat result = Contrast(src, 50.f);
	imshow("original", src);
	imshow("result", result);
	waitKey(0);
	return 0;
}
 
// 對(duì)比度
cv::Mat Contrast(cv::Mat src, int percent)
{
	float alpha = percent / 100.f;
	alpha = max(-1.f, min(1.f, alpha));
	cv::Mat temp = src.clone();
	int row = src.rows;
	int col = src.cols;
	int thresh = 127;
	for (int i = 0; i  row; ++i)
	{
		uchar *t = temp.ptruchar>(i);
		uchar *s = src.ptruchar>(i);
		for (int j = 0; j  col; ++j)
		{
			uchar b = s[3 * j];
			uchar g = s[3 * j + 1];
			uchar r = s[3 * j + 2];
			int newb, newg, newr;
			if (alpha == 1)
			{
				t[3 * j + 2] = r > thresh ? 255 : 0;
				t[3 * j + 1] = g > thresh ? 255 : 0;
				t[3 * j] = b > thresh ? 255 : 0;
				continue;
			}
			else if (alpha >= 0)
			{
				newr = static_castint>(thresh + (r - thresh) / (1 - alpha));
				newg = static_castint>(thresh + (g - thresh) / (1 - alpha));
				newb = static_castint>(thresh + (b - thresh) / (1 - alpha));
			}
			else {
				newr = static_castint>(thresh + (r - thresh) * (1 + alpha));
				newg = static_castint>(thresh + (g - thresh) * (1 + alpha));
				newb = static_castint>(thresh + (b - thresh) * (1 + alpha));
 
			}
			newr = max(0, min(255, newr));
			newg = max(0, min(255, newg));
			newb = max(0, min(255, newb));
			t[3 * j + 2] = static_castuchar>(newr);
			t[3 * j + 1] = static_castuchar>(newg);
			t[3 * j] = static_castuchar>(newb);
		}
	}
	return temp;
}

測(cè)試效果

圖1 原圖

 

圖2 參數(shù)為50的效果圖

圖3 參數(shù)為-50的效果圖

通過(guò)調(diào)整percent可以實(shí)現(xiàn)圖像對(duì)比度的調(diào)整。

到此這篇關(guān)于OpenCV 圖像對(duì)比度的實(shí)踐的文章就介紹到這了,更多相關(guān)OpenCV 圖像對(duì)比度內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • opencv調(diào)整圖像亮度對(duì)比度的示例代碼

標(biāo)簽:蕪湖 紹興 呂梁 蘭州 吉安 安康 廣西 懷化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《OpenCV 圖像對(duì)比度的實(shí)踐》,本文關(guān)鍵詞  OpenCV,圖像,對(duì)比度,的,實(shí)踐,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《OpenCV 圖像對(duì)比度的實(shí)踐》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于OpenCV 圖像對(duì)比度的實(shí)踐的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 国产一区二区精品久久凹凸| 免费视频网站看v片| 欧美成人精品一区二区免费看| 《特殊的精油按摩》6| 四川A片毛片丰满少妇| 国产精品老妇女XX视频| 自拍偷在线精品自拍偷无码| 窝窝人体色www| 性a欧美片| 国产精品久久久久三级| 九七电影97电影理论片韩国| 一区二区在线视频| 黄在线观看www免费看| 成人毛片???91| 性猛交乱婬在线观看免费视频软件| 日本免费二区三区久久| 7777777片毛片免费视频观看| 欧美videos另类色hdfree| 脱美女的内裤摸她的内内| 欧美大肚子孕妇做爰| 日产无码久久久久久精品男男| 性生活直播app| 稚女国产在线XXXX000| 乖女的的乳尖| 美红列车车厢被四男| 女王调奴丨vk| 女人解开乳罩给男人吃奶| 韩国A级高清影片| 亚洲a成人7777777久久| 欧美日本一区二区三区生| 免费无码毛片一区二区A片小说| 欧美日韩一区二区三区免费不卡| 在线免费看污视频| 99在线无码精品秘?入口楼风| 欧美欧美伦院在线观看| 我想看一级黄色大片| 久久这里| 白洁性荡史| 添阴道视频| 浑源县| 久久久久亚洲麻豆|