Iam working on understanding the image with image luminance check and i tried to find the brightness of the image by the code below
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))
Would like to understand how could i get an entire image calculating the luminance of each pixel or a set of them, something similar to what is implemented here at photo-forensics - Luminance Gradient
Error with the implementation
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) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'arithm_op'