import cv2
def area1(image):
list=[]
h,w=image.shape[0],image.shape[1]
for i in range(h):
for j in range(w):
if image[i][j]!=0:
coor=(j,i)
list.append(coor)
return len(list)
def area2(image):
sum=0
h,w=image.shape[0],image.shape[1]
for i in range(h):
for j in range(w):
if image[i][j]==255:
sum+=1
return sum
def area3(image):
sum=0
h,w=image.shape[0],image.shape[1]
for i in range(h):
for j in range(w):
if image[i][j].all()>0:
sum+=1
return sum
if __name__ == '__main__':
image=cv2.imread('temb.png',-1)
print('二值图像白色像素个数(表征面积):',area1(image))
print('二值图像白色像素个数(表征面积):', area2(image))
print('二值图像白色像素个数(表征面积):', area3(image))