OpenCV Decolorization Example: Using Python to convert a color image to a grayscale image

OpenCV Decolorization Example: Using Python to convert a color image to a grayscale image

In computer vision, a grayscale image is a very common image type, which only contains brightness information and does not contain any color information. This type of image is commonly used in applications such as feature extraction, image enhancement, and image segmentation.

OpenCV is a very popular computer vision library that helps us easily convert color images to grayscale images. Here is a code example to convert a color image to grayscale using Python and OpenCV:

import cv2

# 读取彩色图像
img_color = cv2.imread('image.jpg')

# 将彩色图像转换为灰度图像
img_gray = cv2.cvtColor(img_color, cv2.COLOR_BGR2GRAY)

# 显示灰度图像

Guess you like

Origin blog.csdn.net/qq_39605374/article/details/132293520