# How to convert image to grayscale?

How can I convert an image to grayscale? I've got a numpy array of the image and what is the way to convert it? Is there a formula for it?

How can I convert an image to grayscale? I've got a numpy array of the image and what is the way to convert it? Is there a formula for it?

2 Answers

JW

1You can use **OpenCV** function to convert image to **grayscale**.

```
import cv2
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) # or cv2.COLOR_BGR2GRAY
```

This is more accurate mode and is simple.

Reply

JO

1If you want to use the formula, the take a look at the this.

.^{}

This is one of the ways to convert **RGB** image to **grayscale**. It kind of computes the average from the channels. There are different approaches. Here is a link for more details https://en.wikipedia.org/wiki/Grayscale

Reply

Couldn't find what you were looking for?and we will find an expert to answer.

How helpful was this page?