简体   繁体   English

在Python中循环将2D数组转换为RGB图像

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

I want to convert a 2-dimensional array into an image in python using scipy.misc. 我想使用scipy.misc将二维数组转换为python中的图像。 Following is an example what I want to achieve 以下是我要实现的示例

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)

In this code, for each n value I get a 2D array of xs which I am storing in list x. 在这段代码中,对于每个n值,我得到一个xs的二维数组,并将其存储在列表x中。 Instead of storing 2D array xs for each n in x, how can I convert it to an Colour RGB Image, where each value of x between 0.1 and 0.9 would be denoted by different colours ? 而不是为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.

相关问题 将灰度二维 numpy 数组转换为 RGB 图像 - Convert grayscale 2D numpy array to RGB image 在Python中将二维数组转换为彩色图像 - Convert 2d array to collored image in python 在 python 中将图像转换为二维数组 - Convert an image to 2D array in python 我如何在 python 中使用 for 循环打印二维数组中的特定列和行,并且还想将灰色图像更改为 RGB - How I can print specific cols and row from 2d array using for loop in python and also want to change gray image to RGB 如何在Python 3.6中从字节(1D)数组转换为RGB数组(2D)? (NumPy还是SciPy?) - How to convert from bytes (1D) array to RGB array (2D) in Python 3.6? (NumPy or SciPy?) 如何将4d RGB图像数据转换为2d数组以进行LogisticRegression - How to convert 4d RGB image data to 2d array for LogisticRegression 如何对图像进行二进制处理,使用python通过阈值点将零和一分配为2D图像并将其转换为RGB? - how to binaries the image, assign the zeros and one into 2D image by a threshold point using python and convert it to RGB? 从SimpleITK中的3D阵列构建2D RGB图像 - 2D RGB image construction from 3D array in SimpleITK 将二进制图像转换为 Python 中的二维数组或矩阵? - Convert a binary image to 2D array or Matrix in Python? 将具有正值和负值的 2D numpy 数组转换为 RGB 图像 - convert a 2D numpy array with positive and negative values, into an RGB images
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM