How to count number of white and black pixels in color picture in python? How to count total pixels using numpy

后端 未结 4 1386
-上瘾入骨i
-上瘾入骨i 2021-01-21 07:59

I want to calculate persentage of black pixels and white pixels for the picture, its colorful one

import numpy as np
import matplotlib.pyplot as plt

image = cv2         


        
4条回答
  •  再見小時候
    2021-01-21 08:20

    white_pixels = np.logical_and(255==cropped_image[:,:,0],np.logical_and(255==cropped_image[:,:,1],255==cropped_image[:,:,2]))
    
    
    num_white = np.sum(white_pixels)
    

    and the same with 0 for the black ones

提交回复
热议问题