import cv2 def Image_gray(image):#灰度化函数 h, w, ch = image.shape for row in range(h): for col in range(w): b = image[row, col, 0] g = image[row, col, 1] r = image[row, col, 2] k = int(max(b,g,r)) # 取三个通道内的最大值来计算每一个像素值 image[row, col, 0] = k image[row, col, 1] = k image[row, col, 2] = k print("Ok!") cv2.imshow("noise", image) cv2.waitKey(1000) cv2.imwrite("gray.png", image) img=cv2.imread('4.png')#读取图像信息 cv2.imshow('img',img) cv2.waitKey(1000) blur=Image_gray(img)
转载于:
https://blog.csdn.net/qq_49385628/article/details/118935148