python统计图片中黑白像素个数_使用OpenCV计算Python中图像中的黑色像素数

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-22 16:46   48   0

我在

Python中有以下测试代码来读取,阈值和显示图像:

import cv2

import numpy as np

from matplotlib import pyplot as plt

# read image

img = cv2.imread('slice-309.png',0)

ret,thresh = cv2.threshold(img,0,230, cv2.THRESH_BINARY)

height, width = img.shape

print "height and width : ",height, width

size = img.size

print "size of the image in number of pixels", size

# plot the binary image

imgplot = plt.imshow(img, 'gray')

plt.show()

我想用一定的标签来计算图像中的像素数,例如黑色.

我怎样才能做到这一点 ?我查看了OpenCV的教程,但没有找到任何帮助:-(

谢谢!

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP