SHARE
TWEET

Untitled

resta89 Oct 21st, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #importing some useful packages
  2. import matplotlib.pyplot as plt
  3. import matplotlib.image as mpimg
  4. import numpy as np
  5. import cv2
  6. from scipy import ndimage, misc
  7. %matplotlib inline
  8. import math
  9. from skimage import img_as_ubyte
  10.  
  11. def grayscale(img):
  12.     img=cv2.imread('test_images/solidWhiteRight.jpg')
  13.     img=img_as_ubyte(img)
  14.     """Applies the Grayscale transform
  15.     This will return an image with only one color channel
  16.     but NOTE: to see the returned image as grayscale
  17.     (assuming your grayscaled image is called 'gray')
  18.     you should call plt.imshow(gray, cmap='gray')"""
  19.     #return np.dot(img[...,:3], [0.299, 0.587, 0.114])
  20.     #return cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
  21.     # Or use BGR2GRAY if you read an image with cv2.imread()
  22.     return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  23.  
  24. gr=grayscale(img)
  25.  
  26. print (gr.dtype)
  27. gr=np.zeros ((...,...,3))
  28. #plt.imshow(gr,cmap = plt.get_cmap('gray'))
  29. plt.imshow(gr)
  30. plt.show()
RAW Paste Data
Top