2

I have numpy array which shape is (512,512,3)

It is 512 x 512 image.

I want to show image and save as png with matplotlib

How can I do this???

How should I convert??

[[[ 87 48 39]
 [107 43 29]
 [101 40 28]
 ...
 [115 107 100]
 [115 106 100]
 [115 107 102]]
 [[ 94 44 30]
 [106 38 20]
 [ 97 38 23]
 ...
 [114 109 103]
 [113 108 103]
 [114 106 98]]
 [[ 87 41 30]
 [ 96 40 32]
 [ 92 38 37]
 ...
 [114 110 105]
 [114 110 105]
 [116 109 98]]
 ...
 [[123 112 112]
 [140 120 121]
 [135 120 119]
 ...
 [215 191 218]
 [221 195 223]
 [217 196 214]]
 [[127 116 119]
 [134 115 115]
 [138 123 124]
 ...
 [217 195 220]
 [220 199 221]
 [215 193 208]]
 [[125 118 117]
 [127 115 116]
 [131 121 123]
 ...
 [215 199 220]
 [216 198 217]
 [202 179 198]]]
asked May 27, 2021 at 9:24

2 Answers 2

2

You can try the below snip,

from PIL import Image
import numpy as np
# data is your array
img = Image.fromarray(data, 'RGB')
img.save('my.png')
img.show()
answered May 27, 2021 at 9:28
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it works, and it good not having scale.
2
plt.imshow(array)
plt.savefig('filename.png')
answered May 27, 2021 at 9:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.