我写了一个简短的脚本来计算图像中的像素值:
import os
import sys
import cv2
import numpy as np
imn = (sys.argv[1])
a = cv2.imread(imn, 0)
b = cv2.imread(imn, 1)
c = cv2.GaussianBlur(cv2.imread(imn, 0), (7,7), 2)
def NC(img):
y = img.reshape(1, -1)
numA = (y < 127.5).sum()
numB = (y > 127.5).sum()
return ({'less': numA, 'greater': numB})
aa = NC(a)
bb = NC(b)
cc = NC(c)
print "File: {}".format(imn.split('/')[-1])
print "Image: {} - Set: {}".format('A', aa)
print "Image: {} - Set: {}".format('B', bb)
print "Image: {} - Set: {}".format('C', cc)
它完美地工作:
File: ObamaBidenSituationRoom.jpg
Image: A - Set: {'greater': 480558, 'l