opencv学习:实现matlab中的stretchlim函数
来源:互联网 发布:淘宝400 bad request 编辑:程序博客网 时间:2024/04/28 15:29
matlab中的imadjust函数的第一种调用方式为:imadjust(I), I为待处理图像,在参数封装时调用了stretchlim函数。但opencv中没有相应的实现,故参照matlab的源代码实现了stretchlim函数。该函数用了上一篇文章中实现的hist函数,
void stretchlim(const IplImage* img, vector<double> tol, vector<double>& low_high){//接受参数double tol_low , tol_high;switch(tol.size()){case 0://默认值为 0.01, 0.99tol_low = 0.01;tol_high = 0.99;break;case 1:tol_low = tol[0];tol_high = 1-tol[0];break;case 2:tol_low = tol[0];tol_high = tol[1];break;}int nbins = 255;if(img->depth == IPL_DEPTH_16U)nbins = 65535;//若容忍度低值小于高值则观察直方图获取灰度范围if(tol_low<tol_high){//计算直方图vector<long> N = hist(img);//计算累积分布向量vector<double> cdp = cumsumativeDistribution(N);//查找tol_low,tol_high边界灰度值int ilow = lower_bound(cdp.begin(), cdp.end(), tol_low)-cdp.begin();int ihigh = upper_bound(cdp.begin(), cdp.end(), tol_high)-cdp.begin();cout<<tol_low<<endl;cout<<tol_high<<endl;cout<<ilow<<endl;cout<<ihigh<<endl;if(ilow == ihigh)//若边界灰度值相等则设为默认值(当图像为一个平面时){low_high.push_back(0);low_high.push_back(1);}else//否则设为边界灰度归一化值{low_high.push_back(ilow*1.0/nbins);low_high.push_back(ihigh*1.0/nbins);}}//否则设为默认值0,1else{low_high.push_back(0);low_high.push_back(1);}}vector<double> cumsumativeDistribution(vector<long> vec){vector<double> distr;vector<long> cum;long sum = 0;//计算累积向量和总和for(vector<long>::iterator it = vec.begin(); it != vec.end(); it++){sum += *it;cum.push_back(sum);}//计算累积分布率向量for(vector<long>::iterator it = cum.begin(); it != cum.end(); it++){distr.push_back(*it*1.0/sum);}return distr;}
0 0
- opencv学习:实现matlab中的stretchlim函数
- matlab的stretchlim函数
- 图像处理学习笔记之MATLAB中imhist、imadjust、stretchlim函数实现
- opencv实现Matlab中的meshgrid函数
- OpenCV中实现MATLAB中的conv2函数
- opencv实现 Matlab 寻找峰值函数 findpeaks
- opencv实现 Matlab 寻找峰值函数 findpeaks
- OpenCV实现Matlab的fft2、ifft2函数
- OpenCV实现Matlab中的conv2的功能
- opencv中的cvSmooth函数学习
- opencv中的cvCanny函数学习
- matlab实现opencv的pyrDown和pyrUp函数
- MATLAB中imfilter函数用Opencv 实现遇到的若干问题
- OpenCV实现Matlab的circshift、fftshift、ifftshift函数
- 基于Opencv实现Matlab的bwmorph中的bridge操作
- 使用opencv实现matlab中的imfill填充孔洞功能
- DSP using MATLAB中的函数学习
- 【学习OpenCV】与matlab风格一致的函数
- Android xUtils框架(二) ViewUtils
- Android链接服务器问题解答001
- UVa #10285 Longest Run on a Snowboard (习题9-1)
- 程序员必读书单 1.0
- linux mysql 忘记root密码
- opencv学习:实现matlab中的stretchlim函数
- C# 中的委托和事件
- jquery ajax方式获取数据的测试桩
- 机器学习中的范数规则化之(二)核范数与规则项参数选择以及RPCA
- HTTP协议之multipart/form-data请求分析
- C# vs2010代码段(Code Snippets)
- Selenium 1.0 - Metrics Testing - xPath正确但是click方法没有反应
- Head First JQuery学习笔记(三)
- 【原】移动web资源整理