Wednesday, July 29, 2020

Color Space Conversion

In OpenCV, the images are not stored by using the conventional RGB color, rather they are stored in the reverse order i.e. in the BGR order. Hence the default color code while reading an image is BGR. The cvtColor() color conversion function in for converting the image from one color code to other.

Example

Consider this example to convert image from BGR to grayscale.

Import the OpenCV package as shown:
import cv2

Now, for reading a particular image, use the imread() function:

image = cv2.imread('image_flower.jpg')

Now, if we see this image using imshow() function, then we can see that this image is in BGR.

cv2.imshow('BGR_Penguins',image)


Now, use cvtColor() function to convert this image to grayscale.

image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('gray_penguins',image)



Share:

0 comments:

Post a Comment