This script performs basic image processing operations using OpenCV in Python. It loads an image and simultaneously displays the original version alongside grayscale, blurred, and edge-detected outputs.
You need to install the latest version of Python. Download it from the official Python website: https://www.python.org
During installation on Windows, make sure to check the box that says "Add Python to PATH" so you can run Python commands from your command prompt.
This script requires the OpenCV and NumPy libraries. Open your Python IDE terminal, command prompt, or powershell and run:
pip install opencv-python numpy
If you get an error saying "pip is not recognized", you can fix that easily by typing:
python -m pip install opencv-python numpy
- Download the
main.pyscript from this repository. - Place the image you want to process in the exact same folder as your script and rename it to
image.png(or update the filename inside thecv2.imread()line in the code).
- Open your command prompt, powershell, or IDE terminal.
- Navigate to the folder where you saved the script using the
cdcommand:
cd path/to/your/folder
- Run the script by typing:
python main.py
- Open the file in Python IDLE.
- Click on the "Run" tab in the top menu.
- Select "Run Module" (or simply press F5 on your keyboard).
Once running, the script applies the following modifications and opens four separate windows:
- Original: The source color image.
- Grayscale: Converts the image from BGR color to single-channel gray.
- Blur: Applies a Gaussian blur filter to smooth out details.
- Edges: Uses Canny edge detection to highlight structural boundaries.
To close all display windows and exit the program, simply click on any image window and press any key on your keyboard.