opencv中ostu算法
来源:互联网 发布:matlab for mac 2014b 编辑:程序博客网 时间:2024/06/03 19:19
注意mat 与ipilmage读取数据类型的差别。
#include"opencv2/core/core.hpp"#include"opencv2/highgui/highgui.hpp" #include"opencv2/imgproc/imgproc.hpp"using namespace std;using namespace cv;int Otsu(Mat img){ int height = img.rows; #Mat 中读数据的方式类型与Ipilmage中的区别 int width = img.cols; float histogram[256] = {0}; for (int i =0;i<height;i++) { unsigned char *p = (unsigned char *)img.data+img.step*i; for(int j=0;j<width;j++) { histogram[*p++]++; } } int size = height*width; for(int i =0;i<256;i++) { histogram[i] = histogram[i]/size; } float avgValue=0; for (int i=0;i<256;i++) { avgValue += i*histogram[i]; } int threshold; float maxVariance=0; float w=0,u=0; for(int i=0;i<256;i++) { w += histogram[i]; u += i*histogram[i]; float t=avgValue*w - u; float variance = t*t /(w*(1-w)); if(variance>maxVariance) { maxVariance = variance; threshold = i; } } return threshold;}int main(){ Mat img = imread("004.jpg",0); Mat bin_img; int thres = Otsu(img); threshold(img,bin_img,thres,255,THRESH_BINARY); imshow("src",bin_img); waitKey(0); destroyAllWindows();}
阅读全文
0 0
- opencv中ostu算法
- OSTU算法
- ostu算法
- Ostu算法
- opencv学习系列:OSTU算法选自适应阈值
- Ostu算法C#版
- 使用opencv进行Ostu二值化
- OSTU (大津算法)
- ostu
- OSTU
- 毕业课题---之ostu算法二值化
- 基于c++的ostu算法的实现
- matlab 大津算法 ostu 程序
- openCV中canny算法
- opencv中sift算法
- opencv中sift算法
- Ostu算法的Matlab源代码以及程序解析
- OSTU原理及MATLAB和C++算法实现
- 断言
- 31. 数据结构笔记之三十一广义表
- c面试题,那些简单问题里的陷阱!
- Mysql导入excel数据,解决某些字符乱码问题
- spring事务管理
- opencv中ostu算法
- xilinx下载模式
- 第三周项目二 “顺序表”算法库
- Webrtc穿透转发通讯2-windows
- spoj 1812 LCS2(SAM+DP)
- 【SDK使用】sdk print方式
- 第三周项目一(2)
- 45.Scala中Context Bounds代码实战及其在Spark中的应用源码解析
- Spring bean的加载过程