Visitar URL original
learnopencv/otsu-method at master · spmallick/learnopencv · GitHub
Skip to content

Latest commit

 

History

History

otsu-method

README.md

Otsu thresholding separates the foreground and background of an image

Download the Otsu thresholding companion code

This companion implements Otsu thresholding from scratch and compares its threshold and binary output with OpenCV. Both Python and C++ paths are headless, validate their inputs, and resolve default assets relative to this directory.

Requirements

  • Python 3.10–3.14 with OpenCV 4.13 or newer
  • CMake 3.16 or newer
  • A C++17 compiler
  • OpenCV 4 or OpenCV 5 development libraries for the C++ examples

Install the Python dependencies:

python -m pip install -r requirements.txt

Python

Run the custom implementation and the OpenCV reference:

python otsu_implementation.py
python otsu_method.py

Both commands write results under outputs/. Use --help to select another input or output location. No display server is required.

Run the deterministic regression tests:

python -m pytest -q tests/test_otsu.py

C++

cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build --config Release
ctest --test-dir build --output-on-failure -C Release
./build/otsu_implementation
./build/otsu_method

The regression test checks the real boat.jpg fixture, synthetic bimodal data, constant images, invalid inputs, and pixel-for-pixel parity with OpenCV. For boat.jpg, both implementations select threshold 132.


BigVision.AI

Build Production-Ready Computer Vision & AI Solutions

LearnOpenCV is maintained by BigVision.AI, a computer vision and AI consulting company. We help organizations design, build, optimize, and deploy production-ready AI solutions. Our team has deep expertise in computer vision, deep learning, multimodal AI, and edge deployment, with experience solving complex technical challenges across industries.

Have a project in mind? Talk with our expert AI solution builders.

Get in Touch with BigVision.AI