1.原理:
2.实现
def otus(img):m = img.mean()hist = cv2.calcHist([img],[0], # 使用的通道None, # 没有使用mask[65536], # HistSize[0, 65535]) # 直方图柱的范围sigma_both = []for threshold in range(1, 65536):pixel_prob = hist/img.sizew0_threshold = pixel_prob[:threshold].sum()# print("w0_threshold", w0_threshold)w1_threshold = 1 - w0_threshold# print("w1_threshold", w1_threshold)mu0 = hist[:threshold].mean()mu1 = hist[threshold:].mean()sigma_both.append(w0_threshold*math.pow(mu0 - m, 2) + w1_threshold*math.pow(mu1 - m, 2))print("threshold: "sigma_both.index(max(sigma_both)))return sigma_both.index(max(sigma_both))
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!