After advice about detecting focus quality of objects in a photo detected using YoloV3
Here is what I would try on the source image:



Split your image into 5x5 pixel blocks (maybe 3 maybe 7, who knows?)

Create output image one fifth (third, seventh, ??) size

For each block
  For each color channel

    Find best fit plane
    Measure RMS of (pixel value-plane value)

  Next

  Set output pixel to  RMS(R,G,B)

Next



In blurry/plain areas the RMS should be low.  With sharp lines it should be high.

Ced



So, I thought I'd give this a go with 5x5 block.

Here are some results.





Clearly (pun intended), not only is this algorithm an edge detector, but it also a focus metric at those locations.



Those are kind of dim, so I multiplied by 5.







If nothing else, they are kind of cool looking, but I think you can tell where the well focused areas are.



The 5x5 takes a while to process, so I decided to try a 3x3 fit on a simple 4 point gradient estimate (Down from a 16 point gradient estimate).





Still (pun intended again), the blurry lady pic proves this is a focus metric.

Here is the relevant code called for each color channel:


'==================================================================
Public Sub FindFocus(ArgV As Float[]) As Float[]

        Dim w, h, x, y As Integer

        w = ArgV.Bounds[0]
        h = ArgV.Bounds[1]

        Dim theFocus As New Float[w, h]

        For x = 1 To w - 2
          For y = 1 To h - 2
            GoSub CalculateFocusAtPoint
          Next            
        Next

        Return theFocus

'-------------------------------------------------------------------
CalculateFocusAtPoint:

        Dim dx, dy As Integer
        Dim a, b, c As Float

'---- Plane Estimate:  z = ax + by + c

        a = (ArgV[x + 1, y] - ArgV[x - 1, y]) * 0.5
        b = (ArgV[x, y + 1] - ArgV[x, y - 1]) * 0.5
        c = ArgV[x, y]

'---- Calculate the RMS of the NonPlanar

        Dim v, e, s2 As Float

        s2 = 0

        For dx = -1 To 1
          For dy = -1 To 1
            v = a * dx + b * dy + c  
            e = ArgV[x, y] - v
            s2 += e * e
          Next
        Next

'---- Set the Value

        theFocus[x, y] = Sqr(s2 / 9)

        Return
End
'==================================================================




Finally, just because I could, I turned your pic into a "drawing".