Python image is converted into a matrix, matrix data is converted into a picture

# coding=gbk
from PIL import Image
import numpy as np
# import scipy

def loadImage():
    # read image
    im = Image.open("lena.jpg")

    # display image
    im.show()
    
    im = im.convert("L")
    data = im.getdata()
    data = np.matrix(data)
#     print data
    # Convert to 512*512
    data = np.reshape(data,(512,512))
    new_im = Image.fromarray(data)
    # display image
    new_im.show()
    
loadImage()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856740&siteId=291194637