title: Why my image is different being plotted in Opencv-Python?
body: <p>I am trying to take an image and convert it to grayscale, adding some gaussian blur to that image, and detecting the edges. I am having trouble displaying the image with <code>matplotlib</code>'s <code>pyplot</code>.</p>
  <pre><code>import cv2
  import matplotlib.pyplot as plt
  
  def read_image_and_print_dims(image_path):
      &quot;&quot;&quot;Reads and returns image.
      Helper function to examine ow an image is represented&quot;&quot;&quot;
  
      #reading an image
      image=cv2.imread(image_path)
      #printing out some stats and plottin
      print('This image is ',type(image),' with dinmesions',image.shape)
      plt.subplot(2,2,3)
      plt.imshow(image)
      return image
  
  image_path='fall-leaves.png'
  
  img=read_image_and_print_dims(image_path)
  #Make a blurred/smoothed version
  def gaussian_blur(img,kernel_size):
  
      &quot;&quot;&quot;Applies a Gaussian Noise Kernel&quot;&quot;&quot;
      print ('Inside Gaussian')
  
      return cv2.GaussianBlur(img,(kernel_size,kernel_size),4)
  
  #Gray Scale Image
  def grayscale(img):
      &quot;&quot;&quot;Applies the Grayscale transform
          This will return an image with only one color channel
          but NOTE: to see the returned image as grayscale
          you should call plimshow(gray, cmap='gray')&quot;&quot;&quot;
      print ('Inside gray sale')
      return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
  
  # gray scale it
  greyscaled_image = grayscale(img)
  plt.subplot(2, 2, 1)
  
  plt.imshow(greyscaled_image, cmap='gray')
  
  # smooth it a bit with Gaussian blur
  kernal_size = 11
  blur_gray = gaussian_blur(img, kernal_size)
  
  plt.subplot(2, 2, 2)
  plt.imshow(blur_gray)
  
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>
  <p>While running above code in <code>Pycharm</code> it generates following message:</p>
  <pre><code>('This image is ', &lt;type 'numpy.ndarray'&gt;, ' with dinmesions', (320L, 400L, 3L))
  Inside gray sale
  Inside Gaussian
  </code></pre>
  <p>But it doesn't plot the image.</p>
  <h1>EDIT</h1>
  <p>I got it to display using <code>plt.show</code>. However, now I'm having a different problem. I obtained <a href="https://i.stack.imgur.com/UaljT.png" rel="nofollow noreferrer">this figure</a> from <code>pyplot</code>, but using <code>cv2.imshow</code>, I got these: <a href="https://i.stack.imgur.com/Qzxzb.png" rel="nofollow noreferrer">top two images</a>, <a href="https://i.stack.imgur.com/VjBZH.png" rel="nofollow noreferrer">bottom two images</a></p>
  <p>This is my code for <code>plt.show</code>:</p>
  <pre><code>#REad Image
  import numpy as np
  import cv2
  import matplotlib.pyplot as plt
  
  def read_image_and_print_dims(image_path):
      &quot;&quot;&quot;Reads and returns image.
      Helper function to examine ow an image is represented&quot;&quot;&quot;
  
      #reading an image
      image=cv2.imread(image_path)
      #printing out some stats and plottin
      print('This image is ',type(image),' with dinmesions',image.shape)
      plt.subplot(2,2,1)
      #cv2.imshow('Original Image',image)
      plt.imshow(image)
      return image
  
  image_path='fall-leaves.png'
  
  img=read_image_and_print_dims(image_path)
  #Make a blurred/smoothed version
  def gaussian_blur(img,kernel_size):
  
      &quot;&quot;&quot;Applies a Gaussian Noise Kernel&quot;&quot;&quot;
      print ('Inside Gaussian')
  
      return cv2.GaussianBlur(img,(kernel_size,kernel_size),4)
  
  #Gray Scale Image
  def grayscale(img):
      &quot;&quot;&quot;Applies the Grayscale transform
          This will return an image with only one color channel
          but NOTE: to see the returned image as grayscale
          you should call plimshow(gray, cmap='gray')&quot;&quot;&quot;
      print ('Inside gray sale')
      gray_image=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      return gray_image
  
  
  def canny(img,low_threshold,high_threshold):
      &quot;&quot;&quot;Applies the Canny Transform&quot;&quot;&quot;
      return  cv2.Canny(img,low_threshold,high_threshold)
  
  # gray scale it
  greyscaled_image = grayscale(img)
  plt.subplot(2, 2, 2)
  plt.imshow(greyscaled_image)
  #cv2.imshow('grey scale',greyscaled_image)
  
  # smooth it a bit with Gaussian blur
  kernal_size = 11
  blur_gray = gaussian_blur(img, kernal_size)
  
  plt.subplot(2, 2, 3)
  plt.imshow(blur_gray)
  #cv2.imshow('gaussian ',blur_gray)
  
  #Canny image detection
  
  edges_image=canny(blur_gray,50,150)
  
  plt.subplot(2, 2, 4)
  plt.imshow(edges_image)
  plt.show()
  #cv2.imshow('Canny image detection',edges_image)
  #
  # cv2.waitKey(0)
  # cv2.destroyAllWindows()
  </code></pre>
  <p>And this is my code for using <code>cv2.imshow</code>:</p>
  <pre><code>#REad Image
  import numpy as np
  import cv2
  import matplotlib.pyplot as plt
  
  def read_image_and_print_dims(image_path):
      &quot;&quot;&quot;Reads and returns image.
      Helper function to examine ow an image is represented&quot;&quot;&quot;
  
      #reading an image
      image=cv2.imread(image_path)
      #printing out some stats and plottin
      print('This image is ',type(image),' with dinmesions',image.shape)
      #plt.subplot(2,2,3)
      cv2.imshow('Original Image',image)
      return image
  
  image_path='fall-leaves.png'
  
  img=read_image_and_print_dims(image_path)
  #Make a blurred/smoothed version
  def gaussian_blur(img,kernel_size):
  
      &quot;&quot;&quot;Applies a Gaussian Noise Kernel&quot;&quot;&quot;
      print ('Inside Gaussian')
  
      return cv2.GaussianBlur(img,(kernel_size,kernel_size),4)
  
  #Gray Scale Image
  def grayscale(img):
      &quot;&quot;&quot;Applies the Grayscale transform
          This will return an image with only one color channel
          but NOTE: to see the returned image as grayscale
          you should call plimshow(gray, cmap='gray')&quot;&quot;&quot;
      print ('Inside gray sale')
      gray_image=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      return gray_image
  
  
  def canny(img,low_threshold,high_threshold):
      &quot;&quot;&quot;Applies the Canny Transform&quot;&quot;&quot;
      return  cv2.Canny(img,low_threshold,high_threshold)
  
  
  # gray scale it
  greyscaled_image = grayscale(img)
  #plt.subplot(2, 2, 1)
  
  cv2.imshow('grey scale',greyscaled_image)
  
  # smooth it a bit with Gaussian blur
  kernal_size = 11
  blur_gray = gaussian_blur(img, kernal_size)
  
  #plt.subplot(2, 2, 2)
  cv2.imshow('gaussian ',blur_gray)
  
  #Canny image detection
  
  edges_image=canny(blur_gray,50,150)
  
  cv2.imshow('Canny image detection',edges_image)
  
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>
  <p>Different images are obtained using <code>pyplot</code> and <code>cv2</code>. Shouldn't the same image be obtained?</p>