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'
Without further description/clarification from you, I assume you want the gradient of the luminance of the image. So, first we need the luminance image, then the gradient. Note that the example code below is not at all tested, it just gives the general idea of how to proceed.
The luminance is just a synonym for the greyscale image, so depending on your library of choice, you can do:
Or:
You could alternatively convert to HSV and take third channel:
Or:
Now you want the gradient of that, so that could be Sobel, or Scharr:
It looks like the website you link to is mixing that with the original, I am guessing that can be done with something like: