Guest User

Untitled

a guest
Jan 21st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. # importing(bringing-in) the essential libraries
  2.  
  3. # An Open-source library for Computer Vision and image processings, hence the name openCV.
  4. import cv2
  5.  
  6. # To show the image/graphs etc.
  7. import matplotlib.pyplot as plt
  8.  
  9. # Numpy helps us perform matrix (rows and columns of number) operation on images. Since, images are rows and columns of numbers.
  10. import numpy as np
  11.  
  12. #The output of plotting commands is displayed inline within frontends like the Jupyter notebook.
  13. #%matplotlib inline #uncomment %matplotlib inline while using jupyter.
  14.  
  15. # Reading in an image
  16. img = cv2.imread('images.jpg')
  17.  
  18. # Always make a copy while operating on your image, so that your original image doesn't get affected.
  19. img1 = np.copy(img)
  20.  
  21. #openCV reads/brings the image in BGR format (blue channel first, then green and finally red).
  22. #If you plot/show your image using plt.imshow('img1'), it will appear weired.
  23. # Finally plot/show the image
  24. plt.title('weired looking image in BGR format')
  25. plt.imshow(img1)
  26.  
  27. # Reading in an image
  28. img = cv2.imread('images.jpg')
  29.  
  30. # Always make a copy while operating on your image, so that your original image doesn't get affected.
  31. img1 = np.copy(img)
  32.  
  33. #openCV reads/brings the image in BGR format (blue channel first, then green and finally red).
  34. #If you plot/show your image using plt.imshow('img1'), it will appear weired.
  35. # Finally plot/show the image
  36. plt.title('weired looking image in BGR format')
  37. plt.imshow(img1)
  38.  
  39. #So you need to bring it to RGB format.By using cv2.cvtColor(img,cv2.COLOR_BGR2RGB).
  40. img_bgr =np.copy(img)
  41. img_rgb=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
  42.  
  43. plt.title('origional image in RGB format')
  44. plt.imshow(img_rgb)
Add Comment
Please, Sign In to add comment