import numpy as np
import cv2
img = cv2.imread('dataset/mask/00004.png')
img = cv2.resize(img, (128, 128))
GrayImage=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh2=cv2.threshold(GrayImage,127,255,cv2.THRESH_BINARY_INV)
img = np.array(thresh2)
x, y = img.shape
w = 0
b = 0
for row in range(x):
for col in range(y):
if (img[row][col]) == 0:
w = w+1
else:
b = b+1
rate1 = w/(x*y)
rate2 = b/(x*y)
print("白色占比:", round(rate1*100,2),'%')
print("黑色占比:", round(rate2*100,2),'%')
图像
结果
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)