当前位置: 首页 > news >正文

勾线外包网站冯耀宗seo

勾线外包网站,冯耀宗seo,拉萨网站建设系统,苏州有哪些互联网公司两者都是只对单通道使用,对多通道的话 就需要分离通道处理再合并通道 两种方法,第一个要运算次数太多了,第二个只需要查表 伽马矫正函数,这里用第二种方法,且写法有点高级 int gammaCorrection(cv::Mat srcMat, cv::…

两者都是只对单通道使用,对多通道的话 就需要分离通道处理再合并通道

 两种方法,第一个要运算次数太多了,第二个只需要查表

伽马矫正函数,这里用第二种方法,且写法有点高级

int gammaCorrection(cv::Mat srcMat, cv::Mat& dstMat, float gamma) {//建立查询表unsigned char lut[256];for (int i = 0; i < 256; i++){//saturate_cast,防止像素值溢出,如果值<0,则返回0,如果大于255,则返回255lut[i] = saturate_cast<uchar>(pow((float)(i / 255.0f), gamma) * 255.0f);}srcMat.copyTo(dstMat);MatIterator_<uchar> it, end;for (it = dstMat.begin<uchar>(), end = dstMat.end<uchar>(); it != end; it++) {*it = lut[(*it)];}return 0;}

就是建立了查找表,然后计算查找表,再遍历像素直接赋值查找表,就不用计算了。

	int readType = 0;Mat srcMat = imread("kjy.jpg");resize(srcMat, srcMat,Size(srcMat.rows*0.5, srcMat.rows * 0.5));cv::Mat dstMat;float gamma = GAMMA_FACTOR;if (srcMat.type() == CV_8UC1){gammaCorrection(srcMat, dstMat, gamma);}else {Mat channel[3];Mat out[3];float hist[3][256];//通道分离split(srcMat, channel);for (int i = 0; i < 3; i++) {gammaCorrection(channel[i], out[i], gamma);}merge(out, 3, dstMat);}imshow("src", srcMat);imshow("dst", dstMat);waitKey(0);destroyAllWindows();

这就是grammar矫正的代码

直方图均衡化(只对单通道有效果)多通道的话先分离通道再合并一样的

equalizeHist(srcMat, equalizeHistMat);

 

计算直方图函数


int calcIntenHist(const cv::Mat src, float* dstHist)
{//输入必为单通道图if (src.type() != CV_8UC1) {return -1;}memset(dstHist, 0, sizeof(float) * 256);int height = src.rows;int width = src.cols;//指针遍历for (int k = 0; k < height; k++){// 获取第k行的首地址const uchar* inData = src.ptr<uchar>(k);//处理每个像素for (int i = 0; i < width; i++){int gray = inData[i];dstHist[gray]++;}}//直方图归一化float norm = height * width;for (int n = 0; n < 256; n++) {dstHist[n] = dstHist[n] / norm;}return 0;
}

 还进行了归一化

直方图画画函数


int drawIntenHist(cv::Mat& histMat, float* srcHist, int bin_width, int bin_heght)
{histMat.create(bin_heght, 256 * bin_width, CV_8UC3);histMat = Scalar(255, 255, 255);float maxVal = *std::max_element(srcHist, srcHist + 256);for (int i = 0; i < 256; i++) {Rect binRect;binRect.x = i * bin_width;float height_i = (float)bin_heght * srcHist[i] / maxVal;binRect.height = (int)height_i;binRect.y = bin_heght - binRect.height;binRect.width = bin_width;rectangle(histMat, binRect, CV_RGB(255, 0, 0), -1);}return 0;
}

 float height_i = (float)bin_heght * srcHist[i] / maxVal;是防止不够高度大小 要进行的高度归一

直方图均衡化的完整代码:

	float srcHist[256];float dstHist[256];Mat dstHistMat;Mat srcHistMat;Mat histMat[3];Mat equalizeHistMat;cv::Mat dstMat1;int bin_width = 2;int bin_heigth = 100;if (srcMat.type() == CV_8UC1) {equalizeHist(srcMat, equalizeHistMat);imshow("src", srcMat);imshow("equalizeHistMat", equalizeHistMat);waitKey(0);destroyAllWindows();calcIntenHist(dstMat1, dstHist);drawIntenHist(dstHistMat, dstHist, 3, 100);imshow("dstMat hist", dstHistMat);calcIntenHist(srcMat, srcHist);drawIntenHist(srcHistMat, srcHist, 3, 100);imshow("srcMat hist", srcHistMat);waitKey(0);destroyAllWindows();}else{Mat channel[3];Mat out[3];float hist[3][256];split(srcMat, channel);for (int i = 0; i < 3; i++) {equalizeHist(channel[i], out[i]);calcIntenHist(out[i], hist[i]);drawIntenHist(histMat[i], hist[i], bin_width, bin_heigth);//按照channel编号命名窗口stringstream ss;ss << i;string histWindow = "Hist of chanel " + ss.str();string matWindow = "Image of chanel " + ss.str();imshow(histWindow, histMat[i]);imshow(matWindow, out[i]);}merge(out, 3, dstMat1);cv::Mat grayMat;cv::Mat graydstMat;cvtColor(srcMat, grayMat, CV_BGR2GRAY);cvtColor(dstMat1, graydstMat, CV_BGR2GRAY);//计算并绘制直方图calcIntenHist(graydstMat, dstHist);drawIntenHist(dstHistMat, dstHist, 3, 100);imshow("dstMat", dstMat1);imshow("dstMat hist", dstHistMat);calcIntenHist(grayMat, srcHist);drawIntenHist(srcHistMat, srcHist, 3, 100);imshow("srcMat hist", srcHistMat);imshow("srcMat", srcMat);waitKey(0);destroyAllWindows();}return 0;}

http://www.yidumall.com/news/48367.html

相关文章:

  • 行业前10的网站建设公google免费入口
  • html5做的篮球网站如何制作自己的网站
  • 网站怎么做购物车app推广渠道在哪接的单子
  • 怎么做诈骗网站吗长沙做网站推广
  • 哪里做企业网站长沙seo
  • 云南省网站备案要求淘宝seo推广优化
  • 线上培训长春seo技术
  • 促销网站怎么做网络公司取什么名字好
  • 做网站生意多吗软文范例大全1000字
  • 网站建设在什么税控盘网站关键词快速排名工具
  • 县区网站集约化平台建设研究优化大师免费安装下载
  • 建筑设计专业的网站做广告推广哪个平台好
  • 十大个人博客网站今日热搜
  • 做网站须知网络运营课程培训班
  • 昆明网站建设咨询百度搜索怎么优化
  • 做视频的网站靠什么收入安卓手机优化大师官方下载
  • 国内做网站大公司百度网址入口
  • 做单挣钱的网站营销策略ppt模板
  • 怎样做网站推广啊抖音下载百度安装到桌面
  • 江苏做网站xlec深圳优化公司找高粱seo服务
  • 做网站链接怎么做营销型网站名词解释
  • 门户网站 模板电商平台引流推广
  • .net网站架设网络推广文案怎么写
  • 标准化班组建设网站武汉网站搜索引擎优化
  • 做旅游网站的方法中国50强企业管理培训机构
  • ps设计网站百度小说排行榜风云榜单
  • 国外做耳机贸易的平台网站微网站
  • 深圳网站建设网站怎么优化自己网站的关键词
  • 网店都有哪些平台google seo 优化教程
  • 表白制作网站百度站长工具怎么查排名