A = imread('D:\1.png'); figure(1) imshow(A) I = rgb2gray(A); mea1 = mean(I(:)); i = find(I>mea1); mean2 = mean(I(i)); I(I>mean2) = 255; I(I<mean2) = 0; figure(2) imshow(I)把这段MATLAB代码转换成python的
时间: 2023-11-17 13:05:38 浏览: 123
import numpy as np
import cv2
A = cv2.imread('D:\1.png')
cv2.imshow('image', A)
cv2.waitKey(0)
I = cv2.cvtColor(A, cv2.COLOR_BGR2GRAY)
mea1 = np.mean(I)
i = np.where(I > mea1)
mean2 = np.mean(I[i])
I[I > mean2] = 255
I[I < mean2] = 0
cv2.imshow('image', I)
cv2.waitKey(0)
阅读全文