How to convert numpy and Image to each other
This article introduces the relevant knowledge of "how to convert numpy and Image". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
# numpy and Image interchange from PIL import Image import numpy as npim = Image.open ("bryant.jpg") im.show () print ('im type is:', type (im)) # im type is: imgNumPy = np.array (im) # image class to numpyprint ('imgNumPy type is:', type (imgNumPy)) # imgNumPy type is: print ('imgNumPy shape is:', imgNumPy.shape) # imgNumPy is: (667, 1000) 3) print ('minimum of imgNumPy:', imgNumPy.min (), 'maximum of imgNumPy:', imgNumPy.max ()) # imgNumPy: maximum of 0 imgNumPy: 255print (imgNumPy.dtype) # uint8img = Image.fromarray (imgNumPy) # numpy to image class img.show ()
This is the end of the content of "how to convert numpy and Image". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!