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成神之路。
共有 0 条评论