Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import numpy as np
- #... get array s.t. arr.shape = (3,256, 256)
- img = Image.fromarray(arr, 'RGB')
- img.save('out.png')
- >>> arr = np.random.uniform(size=(3,256,257))*255
- >>> arr.T.shape
- (257, 256, 3)
- >>> arr.transpose(1, 2, 0).shape
- (256, 257, 3)
- >>> arr = np.random.uniform(size=(3,256,256))*255
- >>> arr = np.ascontiguousarray(arr.transpose(1,2,0))
- >>> img = Image.fromarray(arr, 'RGB')
- >>> img.save('out.png')
- arr = np.random.uniform(size=(3,256,256))*255
- img = Image.fromarray(arr.T, 'RGB')
- img.save('out.png')
- arr = np.random.uniform(size=(3,256,256))*255
- img = cv2.merge((arr[2], arr[1], arr[0])) # b,g,r
- cv2.imwrite('out.png', img)
Add Comment
Please, Sign In to add comment