Image Conversion to Grayscale Using OpenCV
This project demonstrates a simple Python script that allows users to convert any image into grayscale using OpenCV. Users can input an image path, view the converted grayscale image, and decide whether to save the output. The code is well-commented to enhance understanding.
- Converts any image to grayscale.
- User can view the grayscale image before deciding to save it.
- The output image can be saved in a specified directory by pressing a key.
- Fully commented code for clarity.
- Python: The core programming language.
- OpenCV: Library used for image processing operations.
- Python 3.x
- Required Python libraries:
opencv-python
- Clone the repository:
git clone https://github.com/yourusername/Image-Grayscale-Converter.git cd Image-Grayscale-Converter - Install the required dependency:
pip install opencv-python
-
Run the script:
python grayscale_converter.py
-
When prompted:
- Enter the image file path (e.g.,
C:\Users\YourUsername\Pictures\image.jpg).
- Enter the image file path (e.g.,
-
The grayscale version of the image will be displayed. You can press:
- 's' to save the image (the image will be saved as
output.pngin the default location). - Any other key to close the window without saving the image.
- 's' to save the image (the image will be saved as
Enter path of the image and its name: C:\Users\YourUsername\Pictures\image.jpgAfter the grayscale conversion, if you press 's', the image will be saved as output.png in the specified location.
Feel free to contribute by submitting pull requests or reporting issues.