Console/terminal demo of the OpenCV Sobel edge detector, supporting Windows 11 and Ubuntu Linux 24.04. The input is converted to grayscale and cv2.Sobel computes the gradient in the x and the y direction. A gradient measures how fast the brightness changes, so the x gradient responds most strongly to vertical edges and the y gradient to horizontal ones. The results contain both positive and negative values, so they are computed in signed 16-bit and taken back to 8-bit absolutes with cv2.convertScaleAbs, then blended 50/50 into the combined edge image. Three example images ship under data/ and the results are saved to model/sobel/. 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 (the notebook's example), SC-150.png and sample.png.
  • model/sobel/: the results gray.png, sobel_x.png, sobel_y.png and sobel.png (ship with the Lena examples).
  • tool/tools.py: shared helpers.
  • src/: the demo, the launcher scripts and this document.
  • venv/: Python virtual environment, created by step 1.

[Prerequisites]

  • Operating system: Windows 11 or Ubuntu Linux 24.04.
  • Python 3 and pip.
  • Dependencies are listed in src/requirements.txt and installed by step 1.
  • No GPU required.

[Instructions]

Step 1: create the virtual environment

Delete the old venv/, create a fresh one and install src/requirements.txt. Aborts loudly if pip fails.

 

Windows 11: src\01_venv_create.bat

Ubuntu 24.04: bash src/01_venv_create.sh

 

Step 2: activate the virtual environment

Activate the venv you just created. On Linux, source it so the environment variables apply to the current shell.

 

Windows 11: src\02_venv_activate.bat

Ubuntu 24.04: source src/02_venv_activate.sh

 

Step 3: run the Sobel edge demo

Convert to grayscale, compute the x and y gradients and save the blended result. Extra arguments are forwarded to the Python script.

 

Windows 11: src\03_sobel.bat

Ubuntu 24.04: bash src/03_sobel.sh

Your own image and aperture:

bash src/03_sobel.sh --source data/SC-150.png --ksize 5

 

Step 4: clear the virtual environment (optional)

Delete the venv/ folder to free disk space when you no longer need it.

 

Windows 11: src\99_venv_clear.bat

Ubuntu 24.04: bash src/99_venv_clear.sh

 

[Python Entry Point]

  • src/sobel.py: [--source IMG] [--ksize 3] [--output-dir DIR] [--show].
  • --source: input image, default data/Lena.png.
  • --ksize: the Sobel aperture size, default 3, and it must be odd. Raise it for thicker, smoother edges.
  • --output-dir: output folder, default model/sobel/. --show also opens the results in windows.
  • Saves gray.png (grayscale), sobel_x.png (vertical edges), sobel_y.png (horizontal edges) and sobel.png (the 0.5/0.5 blend).

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