【发布时间】:2020-04-04 09:58:40
【问题描述】:
我正在努力通过图像亮度检查来理解图像,我试图通过下面的代码找到图像的亮度
def brightness( im_file ):
im = Image.open(im_file)
stat = ImageStat.Stat(im)
r,g,b = stat.rms
return math.sqrt(0.241*(r**2) + 0.691*(g**2) + 0.068*(b**2))
想了解如何获得整个图像来计算每个像素或一组像素的亮度,类似于在photo-forensics - Luminance Gradient 实现的内容
执行错误
import cv2
import numpy as np
im = cv2.imread('image.jpeg')
lum = cv2.imread('image.jpeg',cv2.IMREAD_GRAYSCALE)
gradX = cv2.Sobel(lum,cv2.CV_64F,1,0,ksize=5)
gradY = cv2.Sobel(lum,cv2.CV_64F,0,1,ksize=5)
grad = np.sqrt(gradX**2 + gradY**2)
fraction = 0.3
mixed = cv2.addWeighted(im, fraction, grad, 1.0-fraction,0)
cv2.error: OpenCV(3.4.2) /io/opencv/modules/core/src/arithm.cpp:659: error: (-209:Sizes of input arguments do not match) 操作既不是'array op array'(其中数组具有相同的大小和相同的通道数),也不是'array op scalar',也不是函数'arithm_op'中的'scalar op array'
【问题讨论】:
-
图像 -> 2d numpy 数组 -> numpy.gradient 或 numpy.diff
标签: python image image-processing luminance