python-matplotlib-image-numpy- cooperating
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
def loadImage(imgPath):
if not imgPath:
imgPath = r"test.png"
imgObject= Image.open(imgPath)
return imgObject
def showImage(imgObject):
plt.imshow(imgObject)
plt.show()
def imageToArray(imgObject):
""" Image 对象 转为 np.array """
pixelData= np.array(imgObject)
return pixelData
def arrayToImage(pixelData):
""" np.array 转为 Image 对象 """
imgObject = Image.fromarray(pixdata)
return imgObject