Grayscaling is the process of converting an image from other color spaces e.g RGB, CMYK, HSV, etc. to shades of gray. It varies between complete black and complete white.
Importance of grayscaling –
- Dimension reduction: For e.g. In RGB images there are three color channels and has three dimensions while grayscaled images are single dimensional.
- Reduces model complexity: Consider training neural article on RGB images of 10x10x3 pixel.The input layer will have 300 input nodes. On the other hand, the same neural network will need only 100 input node for grayscaled images.
- For other algorithms to work: There are many algorithms that are customized to work only on grayscaled images e.g. Canny edge detection function pre-implemented in OpenCV library works on Grayscaled images only.
Below is the code to Grayscale an image-
Faster code –
- Addition and Blending of images using OpenCV in Python
- Erosion and Dilation of images using OpenCV in python
- Python | Denoising of colored images using opencv
- Python | Create video using multiple images using OpenCV
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Stitching input images (panorama) using OpenCV with C++
- Draw geometric shapes on images using OpenCV
- Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction)
- Working with Images in Python
- Reading images in Python
- Extract images from video in Python
- Apply changes to all the images in given folder - Using Python PIL
- Python | Working with PNG Images using Matplotlib
- Python | Uploading images in Django
- How to download Google Images using Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.