I am extracting the sharpness features of image as shown in the following image mentioned in a paper.


I have done with the following code. Firstly, use the open cv convert the RGB to HSL (luminance is L mentioned in the paper), then get L array. and then used the Laplacian operator to get the LP. Finally, obtain the sharpness value of image based on mathematical form in the paper.

img_HLS = cv2.cvtColor(image, cv2.COLOR_BGR2HLS)
L = img_HLS[:, :, 1]
u = np.mean(L)
LP = cv2.Laplacian(L, cv2.CV_16S, ksize = 3)  
s = np.sum(LP/u) 

I don't know my solution is right or wrong, if there is problem, please help me correct it. Thank!

  • $\begingroup$ That gray_lap should probably be LP (?) $\endgroup$
    – A_A
    Commented Jan 10, 2019 at 9:45
  • $\begingroup$ yes you are right.gray_lap is LP $\endgroup$
    – tktktk0711
    Commented Jan 11, 2019 at 4:51
  • $\begingroup$ @ tktktk0711 If you have a reference to the paper I would be interested. Thanks! $\endgroup$
    – Christophe
    Commented May 20 at 10:08

1 Answer 1


What you have implemented is not what the formula denotes, but what you have implemented will return an indication of Sharpness, possibly with some minor modifications.

The formula produces a single $\mathbb{R}$eal number as the ratio of the local sum of laplacians divided by the local mean. "Local" here refers to a square image patch (of some dimensions) centred around pixel $(x,y)$.

If you forget about the division by $\mu$ for a minute, the $LP(x,y)$ is the sum of the "local" second derivatives. This is a $\mathbb{R}$eal number.

The way you have implemented it, the sum operates over the Laplacian of the whole image.

Furthermore, as the Laplacian is a $\mathbb{R}$eal number and the image is a $\mathbb{N}$atural (bounded) number (a.k.a a non-negative integer), you may experience rounding errors. I say "may" because the matrix used by opencv is also based on integers, so the rounding comes into play at a different region.

Evaluating the Laplacian over the whole image is not so much of a "problem" if that sum you used operates across both dimensions. Usually, in platforms such as GNU Octave, MATLAB and others, a single sum over some matrix, operates across one dimension (usually it sums the columns). Therefore, your s would become a vector...not a $\mathbb{R}$eal number.

Hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.