亚欧色一区w666天堂,色情一区二区三区免费看,少妇特黄A片一区二区三区,亚洲人成网站999久久久综合,国产av熟女一区二区三区

  • 發布文章
  • 消息中心
點贊
收藏
評論
分享
原創

Python將二維數組輸出為圖片

2023-02-22 01:52:02
4
0

 

使用Python讀取二維數組,將二維數組輸出為圖片,并保存在本地。

代碼如下:

# coding=utf8
from PIL import Image
import numpy as np
from scipy import misc
import matplotlib.pyplot as pyplot
?
a = 300
b = 500
x = 20
y = 20
w = 40
h = 80
       
def Gener_mat(a,b,x,y,w,h):             #生成圖片矩陣
   img_mat = np.zeros((a, b), dtype=np.int)
   for i in range(0,a):
       for j in range(0,b):
           img_mat[i][j] = 0
   for i in range(x,x+w):
       for j in range(y,y+h):
           img_mat[i][j] = 1
   return img_mat
?
def out_img(data):                 #輸出圖片
   new_im = Image.fromarray(data)     #調用Image庫,數組歸一化
   #new_im.show()
   pyplot.imshow(data)                  #顯示新圖片
   misc.imsave('new_img.jpg', new_im)   #保存圖片到本地
?
?
img_mat = Gener_mat(a,b,x,y,w,h)
out_img(img_mat)

 

0條評論
0 / 1000
代碼的路
100文章數
1粉絲數
代碼的路
100 文章 | 1 粉絲
代碼的路
100文章數
1粉絲數
代碼的路
100 文章 | 1 粉絲
原創

Python將二維數組輸出為圖片

2023-02-22 01:52:02
4
0

 

使用Python讀取二維數組,將二維數組輸出為圖片,并保存在本地。

代碼如下:

# coding=utf8
from PIL import Image
import numpy as np
from scipy import misc
import matplotlib.pyplot as pyplot
?
a = 300
b = 500
x = 20
y = 20
w = 40
h = 80
       
def Gener_mat(a,b,x,y,w,h):             #生成圖片矩陣
   img_mat = np.zeros((a, b), dtype=np.int)
   for i in range(0,a):
       for j in range(0,b):
           img_mat[i][j] = 0
   for i in range(x,x+w):
       for j in range(y,y+h):
           img_mat[i][j] = 1
   return img_mat
?
def out_img(data):                 #輸出圖片
   new_im = Image.fromarray(data)     #調用Image庫,數組歸一化
   #new_im.show()
   pyplot.imshow(data)                  #顯示新圖片
   misc.imsave('new_img.jpg', new_im)   #保存圖片到本地
?
?
img_mat = Gener_mat(a,b,x,y,w,h)
out_img(img_mat)

 

文章來自個人專欄
文章 | 訂閱
0條評論
0 / 1000
請輸入你的評論
2
2