2

this is my first question, any criticism is welcome.

I've been trying to implement the sharpness estimator presented in section 2.2 of this paper, using Python and OpenCV, but haven't been very succesful.

First I load the Original Image:

Original Image

and crop the face using the landmarks, resulting in this Landmark Cropped Picture

Landmark Cropped Picture.

Then I run the custom Laplace Filters presented on the paper:

# Custom kernels for laplace filter
kernel1 = np.array([[1, -2, 1]])
kernel2 = np.array([[1],
                    [-2],
                    [1]])
# Use custom Laplace filter to obtain contours and edges, the more sharp an 
# image is the greater the response from the laplace filter
pass1 = cv2.filter2D(cropped_image, cv2.CV_32F, kernel1)
pass2 = cv2.filter2D(cropped_image, cv2.CV_32F, kernel2)
# Get the magnitude (absolute value) of pass1 and pass2
pass1 = np.absolute(pass1)
pass2 = np.absolute(pass2)
# Sum the response from both filters
lap_sum = cv2.add(pass1, pass2, dtype=cv2.CV_32F)

Here's where things seem to go wrong, the expected result would look something like this:

this

but I get this instead:

this instead.

Furthermore, the paper says that the final measure is the

"averaged Laplace operator response by masked image"

and that the score should fall in the interval of [0.0, 1.0]. However for that to happen I had to average only non-zero pixels and normalize the final score, and even then I get an abismal score of 0.1 that I think should be higher for the picture I used in this example.

I have implemented it on colab if you want to run it yourself, should be easier to interpret my results seeing the code and the pictures. Thank you very much.

Cassio-4
  • 21
  • 2
  • Your Laplace result seems right, though you are clipping the negative values in the display, and so only seeing the positive ones. The result from the paper doesn’t look at all like a Laplace result. – Cris Luengo Jan 13 '22 at 15:11
  • 2
    Oh, in the paper they add the magnitude (absolute value) of `pass1` and `pass2`. That is the modification to the Laplace they talk about. Your implementation is a correct Laplace (som of second derivatives). – Cris Luengo Jan 13 '22 at 15:14
  • Thanks for your comment @CrisLuengo. I tried doing `pass1 = cv2.filter2D(cropped_image, cv2.CV_32F, kernel1) pass2 = cv2.filter2D(cropped_image, cv2.CV_32F, kernel2) pass1 = np.abs(pass1) pass2 = np.abs(pass2) lap_sum = cv2.add(pass1, pass2, dtype=cv2.CV_32F)` But still don't really get the expected results, is that what you meant? – Cassio-4 Jan 14 '22 at 00:29
  • That is what they say they did, but who knows what they actually did? Many papers like this are poorly written and impossible to reproduce. Good luck! :) – Cris Luengo Jan 14 '22 at 00:42
  • Yeah.. Still, you brought to my attention a great detail I missed, thank you very much! I'll update the code and question. – Cassio-4 Jan 14 '22 at 01:21
  • 1
    Good question, please answer your own question so people can easiy reach it. – Yunus Temurlenk Jan 14 '22 at 07:19

0 Answers0