Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #This program loads an image, displays it, and then creates, displays
  2.  
  3. #and saves a new image that has only the green channel displayed.
  4.  
  5.  
  6. #Import the packages for images and arrays:
  7.  
  8. import matplotlib.pyplot as plt
  9.  
  10.  
  11. inputFile = input("Enter name of the input file: ")
  12.  
  13. outputFile = input("Enter name of the output file: ")
  14.  
  15.  
  16. img = plt.imread(inputFile)
  17. #Read in image from csBridge.png
  18.  
  19.  
  20. img2 = img.copy()
  21. #make a copy of our image
  22. img2[:,:,0] = 0
  23. #Set the green channel to 0
  24. img2[:,:,2] = 0
  25. #Set the blue channel to 0
  26.  
  27.  
  28. plt.imsave(outputFile, img2)
  29. #Save the image we created to the file: reds.png
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement