python矩阵图像rgb_从numpy数组转换为RGB图像

本文介绍如何将三个numpy数组作为红、绿、蓝组件转换为RGB图像。遇到的问题是直接使用numpy数组生成的图像显示为噪点。解决方法是将数组归一化到0到255的范围,然后使用PIL库的Image.fromarray方法创建图像。
摘要由CSDN通过智能技术生成

I have three (241, 241) numpy arrays which I would like to treat as the Red, Green and Blue components of an image.

I have tried this:

import numpy as np

from PIL import Image

arr = np.zeros((len(x), len(z), 3))

arr[:,:,0] = red_arr

arr[:,:,1] = green_arr

arr[:,:,2] = blue_arr

img = Image.fromarray(arr, 'RGB')

img.show()

But the resulting image just looks like noise:

Can anyone tell me what I am doing wrong please?

As an example, my red_arr is an array of floats that looks like this:

解决方案

In your comment you specify that the red_arr, etc. are arrays of the range -4000 to 4000.

But if we take a look at the specifications of the Image.from_array modes, then

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值