如下所示:
# coding=gbkfrom PIL import Imageimport numpy as np# import scipydef loadImage(): # 讀取圖片 im = Image.open("lena.jpg") # 顯示圖片 im.show() im = im.convert("L") data = im.getdata() data = np.matrix(data)# print data # 變換成512*512 data = np.reshape(data,(512,512)) new_im = Image.fromarray(data) # 顯示圖片 new_im.show() loadImage()
上面要先對圖片去除顏色,就是變成黑白的,轉換成二維數(shù)據(jù)矩陣,不去顏色的還要保存顏色的,然后后面轉換就不行了,下面利用Image.fromarray(data) 新建圖片
轉換后
以上這篇Python圖片轉換成矩陣,矩陣數(shù)據(jù)轉換成圖片的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答