CONVERT AN IMAGE INTO GRAYSCALE USING OPENCV PYTHON

In this tutorial, we will discuss how to convert an image into grayscale using opencv library in python program. In python programming language convert an image into grayscale using opencv library in python is very simple than other programming language. In python program any code is very simple and well understand than other programming language.

  • Prerequisite: Install the pillow library, to run the following statements:
pip install opencv-python

Importance of gray scaling

  • Dimension reduction: For example, in RGB images there are three color channels and three dimensions while grayscale images are single dimensional.
  • Reduces model complexity: Consider training neutral articles on RGB images of 10*10*3 pixels.
  • For other algorithm to work: Many algorithm are customized to work only on grayscale image.
  • Final code will be like this:
import cv2
img=cv2.imread("https://www.codespeedy.com/wp-content/themes/CodeSpeedy-March-2019/img/logo/CodeSpeedy-Logo.png",0)
cv2.imshow("image",img)
  • Final  output:
    Image will be present in Black colour

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top