Guest User

Untitled

a guest
Dec 10th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. from PIL import Image
  2. import numpy as np
  3.  
  4. #... get array s.t. arr.shape = (3,256, 256)
  5. img = Image.fromarray(arr, 'RGB')
  6. img.save('out.png')
  7.  
  8. >>> arr = np.random.uniform(size=(3,256,257))*255
  9.  
  10. >>> arr.T.shape
  11. (257, 256, 3)
  12.  
  13. >>> arr.transpose(1, 2, 0).shape
  14. (256, 257, 3)
  15.  
  16. >>> arr = np.random.uniform(size=(3,256,256))*255
  17. >>> arr = np.ascontiguousarray(arr.transpose(1,2,0))
  18. >>> img = Image.fromarray(arr, 'RGB')
  19. >>> img.save('out.png')
  20.  
  21. arr = np.random.uniform(size=(3,256,256))*255
  22. img = Image.fromarray(arr.T, 'RGB')
  23. img.save('out.png')
  24.  
  25. arr = np.random.uniform(size=(3,256,256))*255
  26. img = cv2.merge((arr[2], arr[1], arr[0])) # b,g,r
  27. cv2.imwrite('out.png', img)
Add Comment
Please, Sign In to add comment