大津法python
来源:互联网 发布:高德地图数据导出 编辑:程序博客网 时间:2024/06/09 23:16
http://blog.csdn.net/u012771236/article/details/44975831
import numpy as np def OTSU_enhance(img_gray, th_begin=0, th_end=256, th_step=1): assert img_gray.ndim == 2, "must input a gary_img" max_g = 0 suitable_th = 0 for threshold in xrange(th_begin, th_end, th_step): bin_img = img_gray > threshold bin_img_inv = img_gray <= threshold fore_pix = np.sum(bin_img) back_pix = np.sum(bin_img_inv) if 0 == fore_pix: break if 0 == back_pix: continue w0 = float(fore_pix) / img_gray.size u0 = float(np.sum(img_gray * bin_img)) / fore_pix w1 = float(back_pix) / img_gray.size u1 = float(np.sum(img_gray * bin_img_inv)) / back_pix # intra-class variance g = w0 * w1 * (u0 - u1) * (u0 - u1) if g > max_g: max_g = g suitable_th = threshold return suitable_th
#include "opencv2\opencv.hpp" #include <iostream> using namespace std;using namespace cv;int main() { Mat frame = imread("11.png"); imshow("src", frame); cvtColor(frame, frame, COLOR_BGR2GRAY);//图像灰度化 threshold(frame, frame, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);//大津法 imshow("大津法", frame); waitKey(0); return 0;}
阅读全文
0 0
- 大津法python
- 大津法(Python实现)
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- 求字符串最后一个单词的长度
- 安装numpy笔记
- stm32在rt-thread上的SysTick(系统定时器)
- 解决linux下tomcat8上传图片无法通过Nginx查看的问题
- 高并发压力下nginx动静分离、nginx代理缓存两种模式的性能比较
- 大津法python
- Unity3D中物体的碰撞和移动所需函数与数据
- 使用RDO搭建OpenStack POC环境
- 单向链表的创建与遍历
- 第三周项目4
- mybatis入门--以新人的角度看问题
- hibernate4使用原生jdbc进行批处理
- 翻转数组(C语言实现)
- Cocoapods 错误