A console/terminal demo of OpenCV erosion, supporting Windows 11 and Ubuntu Linux 24.04. The image is converted to grayscale, binarized with a global threshold, and then processed with cv2.erode at several kernel sizes, 5×5 and 11×11 by default. Erosion is the opposite of dilation: it shrinks the white regions by the structuring element, which is commonly used to remove small specks of noise or to separate objects that touch each other. Two example images ship under data/ (Lena and sample), and the results are saved to model/erosion/. 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/erosion/: the results gray.png (grayscale), binary.png (binarized), erosion_5x5.png and erosion_11x11.png (the two kernel sizes); 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 erosion demo
Run the demo. Any extra arguments are forwarded to the program.
Windows: src\03_erosion.bat
Linux: bash src/03_erosion.sh
To use your own image and parameters, for example:
bash src/03_erosion.sh --source data/sample.png --kernel-sizes 3,7 --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/erosion.py: [--source IMG] [--threshold 110] [--max-value 255] [--kernel-sizes 5,11] [--iterations 1] [--output-dir DIR] [--show]. The defaults are a threshold of 110, a max value of 255, all-ones square kernels of 5×5 and 11×11, and 1 iteration. --kernel-sizes takes a comma-separated list, and the program writes one erosion_NxN.png per size. It saves gray.png, binary.png and those results to model/erosion/; --show also opens the results in windows.
[References]
- OpenCV morphological transformations tutorial: https://docs.opencv.org/4.x/d9/d61/tutorial_py_morphological_ops.html
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.