-3

I am following this course on computer vision: https://in.udacity.com/course/introduction-to-computer-vision--ud810

The instructor explains how gaussian filter causes blurring of image. The instructor uses matlab to demonstrate it but I am using python 3 with opencv. I ran the following code:

import cv2
from matplotlib import pyplot as pl

image = cv2.imread("Desert.jpg")
blur = cv2.GaussianBlur(image,(95,95),5)
cv2.imshow("desert", image)
pl.imshow(blur)
pl.xticks([]), pl.yticks([])
pl.show()

This is the original image:
Original image

And this is is the "blur" image:
"blur" image

The image is blurred, no doubt. But how colors have interchanged ? The mountain is blue while the sky is brick red ?

Nyerguds
  • 5,360
  • 1
  • 31
  • 63
Parth
  • 39
  • 10

1 Answers1

1

Because you plot one with opencv and another with matplotlib.

The explanation given here is as follows:

There is a difference in pixel ordering in OpenCV and Matplotlib. OpenCV follows BGR order, while matplotlib likely follows RGB order.

Since you read and show the image with opencv, it is in BGR order and you see nothing wrong. But when you show it with matplotlib it thinks that the image is in RGB format and it changes the order of blue and red channels.

Community
  • 1
  • 1
seleciii44
  • 1,529
  • 3
  • 13
  • 26