A console/terminal demo of the OpenCV bilateral filter, supporting Windows 11 and Ubuntu Linux 24.04. Salt-and-pepper noise is added to the input image and then removed with cv2.bilateralFilter. Because the bilateral filter also weighs the color difference between pixels while it smooths, it removes the noise while preserving the edges, instead of blurring them away as an ordinary blur would. Two example images ship under data/ (Lena and sample), and the results are saved to model/bilateral/. No GPU is involved.

 

[Folder Structure]

  • CLAUDE.md / AGENT.md: program specification (identical content).
  • CHANGELOG.md: change log.
  • copyright.txt: copyright notice.
  • data/: the example images Lena.png and sample.png.
  • model/bilateral/: the results noise.png (the noisy image) and bilateral.png (the filtered image); the Lena examples are included.
  • tool/tools.py: shared helpers.
  • src/: the demo, the launcher scripts and this document.
  • venv/: Python virtual environment, created by step 01.

[Prerequisites]

  • Operating system: Windows 11 or Ubuntu Linux 24.04.
  • Python 3 and pip.
  • No GPU required; an ordinary CPU is enough.

[Instructions]

Step 1: Create the virtual environment

Delete the old venv/, create a fresh one and install the packages listed in src/requirements.txt. The script aborts loudly if pip fails.

 

Windows: src\01_venv_create.bat

Linux: bash src/01_venv_create.sh

Step 2: Activate the virtual environment

Activate the venv. On Linux, source the script.

 

Windows: src\02_venv_activate.bat

Linux: source src/02_venv_activate.sh

Step 3: Run the bilateral-filter demo

Run the demo. Any extra arguments are forwarded to the program.

 

Windows: src\03_bilateral_filter.bat

Linux: bash src/03_bilateral_filter.sh

To use your own image and parameters, for example:

bash src/03_bilateral_filter.sh --source data/sample.png --noise-count 3000 --d 9

 

Step 4: Remove the virtual environment

Delete the venv/ folder.

 

Windows: src\99_venv_clear.bat

Linux: bash src/99_venv_clear.sh

[Python Entry Point]

  • src/bilateral_filter.py: [--source IMG] [--noise-count 1000] [--seed 0] [--d 5] [--sigma-color 150] [--sigma-space 150] [--output-dir DIR] [--show]. The defaults are data/Lena.png with 1000 noise pixels and bilateralFilter(d=5, sigmaColor=150, sigmaSpace=150). It saves noise.png and bilateral.png to model/bilateral/; --show also opens the results in windows. The noise is seeded, so the output is reproducible.

[References]

 

This SDK is built in AppForAI - AI Dev Tools.

 

Purchase license separately:  USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.