python: how to compute the sharpness features of image

asked 2019-01-08 20:49:41 -0500

bubu_ka gravatar image

updated 2019-01-09 00:16:49 -0500

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(gray_lap/u)

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

edit retag flag offensive close merge delete


hmm, local vs global mean value ..

berak gravatar imageberak ( 2019-01-08 22:47:31 -0500 )edit

@berak could you tell me your comment in detail. what's local vs global mean value ?

bubu_ka gravatar imagebubu_ka ( 2019-01-08 23:07:45 -0500 )edit

you are using the single, global mean value frm the image, while the paper mentions "local" mean, which probably means: sample a x-neighbourhood around pixel at xy, and take the mean from there

berak gravatar imageberak ( 2019-01-09 02:02:11 -0500 )edit

thanks for your comments, how to compute it with python.

bubu_ka gravatar imagebubu_ka ( 2019-01-09 03:34:55 -0500 )edit

For sharpness: LP = cv2.Laplacian(L, cv2.CV_64F).var()

supra56 gravatar imagesupra56 ( 2019-01-09 03:42:20 -0500 )edit

@supra56, the "local mean" is the problem, now ;)

(and var() is the global variance, not the local mean)

berak gravatar imageberak ( 2019-01-09 03:43:51 -0500 )edit