A console/terminal demo of OpenCV dilation, supporting Windows 11 and Ubuntu Linux 24.04. The image is converted to grayscale, binarized with a global threshold, and then processed with cv2.dilate, which grows the white regions by the structuring element. Dilation is commonly used to fill small holes inside an object or to reconnect broken lines. Two example images ship under data/ (Lena and sample), and the three results are saved to model/dilation/. 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/dilation/: the results gray.png (grayscale), binary.png (binarized) and dilation.png (the dilated 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 dilation demo

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

 

Windows: src\03_dilation.bat

Linux: bash src/03_dilation.sh

To use your own image and parameters, for example:

bash src/03_dilation.sh --source data/sample.png --kernel-size 9 --iterations 2

 

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/dilation.py: [--source IMG] [--threshold 110] [--max-value 255] [--kernel-size 5] [--iterations 1] [--output-dir DIR] [--show]. The defaults are a threshold of 110, a max value of 255, a 5×5 all-ones kernel and 1 iteration; more iterations grow the white regions further. It saves gray.png, binary.png and dilation.png to model/dilation/; --show also opens the results in windows.

[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.