簡體   English   中英

在Python中循環將2D數組轉換為RGB圖像

[英]Convert 2D array into RGB image in a loop in Python

我想使用scipy.misc將二維數組轉換為python中的圖像。 以下是我要實現的示例

import numpy as np
from scipy.misc import toimage, imsave

L = 20      # one side of lattice
N = L*L     # number of sites in the lattice
xs = np.zeros((L,L), float)

x = []
for n in range(100):
    for i in range(L):
        for j in range(L):
            xs[i,j] = np.random.uniform(0.1, 0.9)
            x.append(xs)

在這段代碼中,對於每個n值,我得到一個xs的二維數組,並將其存儲在列表x中。 而不是為x中的每個n存儲2D數組xs,我如何將其轉換為彩色RGB圖像,其中x的值在0.1到0.9之間將用不同的顏色表示?

import numpy as np
import matplotlib.pyplot as plt

L = 20      # one side of lattice
N = L*L     # number of sites in the lattice
xs = np.zeros((L, L), float)

for n in range(100):
    for i in range(L):
        for j in range(L):
            xs[i,j] = np.random.uniform(0.1, 0.9)
            plt.imshow(xs)
plt.colorbar()
plt.savefig('temp.png')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM