Blurring and Grayscaling and Image

Learn how to convert an image into grayscale and blur it for processing.

Two important functions in image processing are blurring and grayscaling. Many image processing operations take place on grayscale (black and white) images, as they are simpler to process.

Similarly, blurring is also useful for edge detection, as we’ll see in later examples.

Converting an image to grayscale

The first argument is the image as shown in line 8 of the code block below.

Next, we’ll convert it to grayscale in line 11 of the code widget below.

First, we’ll convert the image to gray by using the cvtColor() function. The two arguments are:

  1. Image: The image to be converted.

  2. COLOR_BGR2GRAY: The colors mode.

COLOR_BGR2GRAY stands for “blue, green, red to gray.”

We must have heard of the RGB color scheme. OpenCV does it the other way round- so blue is first, then green, then red.

Get hands-on with 1200+ tech skills courses.