我是靠谱客的博主 激动枕头,这篇文章主要介绍python实现大津算法,现在分享给大家,希望可以做个参考。

参考博文:https://blog.csdn.net/u012771236/article/details/44975831
size:图像总像素个数
u:图像的平均灰度
w0:前景像素点占整幅图像大小的比例
u0:前景像素点的平均值
w1:背景像素点占整幅图像大小的比例
u0:背景像素点的平均值
g:类间方差

u = w0 * u0 + w1 * u1 (1)
g = w0*(u - u0)^2 + w1*(u - u1)^2 (2)
将(1)代入(2)得:
g = w0 * w1 * (u0 - u1)^2

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import numpy as np import cv2 import matplotlib.pyplot as plt # plt 用于显示图片 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 range(th_begin, th_end, th_step): bin_img = img_gray > threshold print(bin_img) bin_img_inv = img_gray <= threshold fore_pix = np.sum(bin_img) back_pix = np.sum(bin_img_inv) if 0 == fore_pix:

最后

以上就是激动枕头最近收集整理的关于python实现大津算法的全部内容,更多相关python实现大津算法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部