Otsu图像分割

opencv自带Otsu算法,只需要在分割时将参数选择为“cv2.THRESH_OTSU”即可
#coding:utf-8
import cv2
import numpy as np
from matplotlib import pyplot as plt

image = cv2.imread('E:/shale10053.bmp')
grayimage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(grayimage, (3,3), 0)

plt.figure(figsize=(5,5))
plt.subplot(), plt.imshow(image, "gray")
plt.title("source image"), plt.xticks([]), plt.yticks([])

ret1, th1 = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU) #方法选择为THRESH_OTSU

plt.f

Otsu图像分割最先出现在Python成神之路

版权声明:
作者:Alex
链接:https://www.techfm.club/p/28832.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>