import numpy as np img = np.array([ [255, 255, 0, 0 ], [255, 255, 0, 0 ], [0, 0, 255, 255], [0, 0, 255, 255] ], dtype=np.uint8) white_count = np.sum(img == 255) black_count = np.sum(img == 0)