I'm thinking of pixelize + threshold, but I need a more formalized way of finding the darkest spots on the photo, with tweakable parameters.
Something I can think of is the parts with lowest spatial frequency and least luminous pixels together, i.e. the spots with darkest pixels spread over a largest area (on average) should win but small black dots should be considered too, with some sort of adaptive weighing.
desired result; left image transformed to right image:
luminance bitmap transformed into contrast 'kernels'

UPD: The required result is, in fact, a metric. Which should be a ratio of locally cumulated contrast over a known area.
Local points of negligibly small size should not count, no matter how contrast they are; bigger areas with mediocre contrast features should win [because their cumulative luminosity power is higher]. The closest thing I can think of is a 2D probability distribution function; kernelized, smoothed out, spatially-oriented.

  • $\begingroup$ it's not quite clear what you're looking for. Maybe adding a picture and clearly marking in it what these "spots" are would help. $\endgroup$ Oct 20, 2020 at 20:29
  • $\begingroup$ @MarcusMüller i need result similar to the image in the description, but strictly parameterized and comparable; what i do not need: edge detection / median luminosity calculation; what i do need: finding and quantifying areas with highest contrast $\endgroup$
    – ivan866
    Oct 20, 2020 at 20:52
  • $\begingroup$ I'm confused: your question says you want the biggest contiguous dark area. That's something with a very low contrast. Could you maybe explain what kind of contrast you mean? $\endgroup$ Oct 20, 2020 at 21:04
  • $\begingroup$ @MarcusMüller i need areas with highest contrast over a largest area possible ratio; i.e. contrast of 50% over 100 pixels radius counts equally same as contrast of 100% over 3 pixels wide area; i need contrast 'kernels', as i call them; perhaps some spectral methods will do $\endgroup$
    – ivan866
    Oct 20, 2020 at 21:09
  • 1
    $\begingroup$ hence the "kind of"; please, really, add this to your question's text, it's crucial! $\endgroup$ Oct 20, 2020 at 21:24

1 Answer 1


Pass a sliding window of eg 100x100 pixels over the image stepped 1 pixel at a time in each dimension. Note the maximum and the minimum pixel value. The local contrast is now the local_max/local_min.

A more robust method might be to use a tapered window (eg Gaussian) and a sliding histogram, using eg the 10-percentile and 90-percentile to avoid salt and pepper noise corrupting results.

If (as stated in your update) you are interested in contrast of features larger than a pixel, downsample your image first.


  • $\begingroup$ so, basically a convolution $\endgroup$
    – ivan866
    Oct 21, 2020 at 6:17
  • $\begingroup$ Yeah a convolution except that you are tracking the min/max of the delayline rather than the sum. $\endgroup$
    – Knut Inge
    Oct 21, 2020 at 14:10

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.