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

后端 未结 4 1273
-上瘾入骨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:25

    Keep variables for white_count and black_count and just iterate through the image matrix. Whenever you encounter 255 increase the white_count and whenever 0 increase the black_count. Try it yourself, if no success I'll post the code here :)

    P.S keep the dimensionality of the image in mind

提交回复
热议问题