79385988

Date: 2025-01-25 00:42:14
Score: 0.5
Natty:
Report link

You asked for a suggestion, here are a few.

The algorithm you described is a Global Thresholding approach, which you have hardcoded a threshold instead of using a quality algorithm to generate the threshold for you, such as Otsu. I would highly advise you using Otsu instead.

Note: Alex's answer uses OpenCV. If you liked that answer, you can tell it to use Otsu instead.

See: https://docs.opencv.org/3.4/d7/d4d/tutorial_py_thresholding.html

My second suggestion is to not write it yourself, and also not to use Global Thresholding, but Local Adaptive Thresholding. OpenCV offers this too, but only elementary implementations like "Mean". Popular PHD researched algorithms include: Sauvola, Niblack, Wolf, NICK, etc. There are other Python packages for these too, like DoxaPy.

Note: Local Adaptive algorithms usually take parameters. The defaults are typically good enough, but you can optimize them for your needs.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Brandon Petty