A console/terminal demo of the OpenCV basic linear transform for brightness and contrast, supporting Windows 11 and Ubuntu Linux 24.04. Each pixel is computed as new = clip(alpha × src + beta, 0, 255), where alpha scales the contrast and beta shifts the brightness, with values clipped to the 0 to 255 range. Two example images ship under data/ (Lena and sample), and the result is saved to model/brightness/. 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/brightness/: the result brightness.png; the Lena example is 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: Adjust the brightness and contrast
Run the brightness and contrast demo. Any extra arguments are forwarded to the program.
Windows: src\03_brightness.bat
Linux: bash src/03_brightness.sh
To use your own image and parameters, for example:
bash src/03_brightness.sh --source data/sample.png --alpha 1.2 --beta 80
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/brightness.py: [--source IMG] [--alpha 2.0] [--beta 50] [--output-dir DIR] [--show]. alpha is the contrast factor (a useful range is 1.0 to 3.0) and beta the brightness offset (0 to 100). The earlier example prompted for these two values interactively; here they are arguments. It saves brightness.png to model/brightness/; --show also opens the result in a window. Large alpha values saturate the bright channels by design.
[References]
- OpenCV basic linear transform tutorial: https://docs.opencv.org/master/d3/dc1/tutorial_basic_linear_transform.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.