python - 在 Python 中将 3 个单独的 numpy 数组组合为 RGB 图像

标签 python image image-processing numpy

所以我有一组数据,我可以将其转换为 R、G、B 波段的单独 numpy 数组。现在我需要将它们组合起来形成一个 RGB 图像。

我尝试使用“图像”来完成这项工作,但它需要归因于“模式”。

我试着做一个把戏。我会使用 Image.fromarray() 将数组转换为图像,但是当 Image.merge 需要“L”模式图像进行合并时,默认情况下它会达到“F”模式。如果我首先将 fromarray() 中的数组属性声明为“L”,那么所有的 R G B 图像都会失真。

但是,如果我保存图像然后打开它们然后合并,它工作正常。 Image 以“L”模式读取图像。

现在我有两个问题。

首先,我不认为这是一种优雅的工作方式。所以如果有人知道更好的方法,请告诉

其次,Image.SAVE 无法正常工作。以下是我面临的错误:

In [7]: Image.SAVE(imagefile, 'JPEG')
----------------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

/media/New Volume/Documents/My own works/ISAC/SAMPLES/<ipython console> in <module>()

TypeError: 'dict' object is not callable

请提出解决方案。

请注意,图像大约是 4000x4000 大小的数组。

最佳答案

rgb = np.dstack((r,g,b))  # stacks 3 h x w arrays -> h x w x 3

还要将 float 0 .. 1 转换为 uint8 s,

rgb_uint8 = (np.dstack((r,g,b)) * 255.999) .astype(np.uint8)  # right, Janna, not 256

关于python - 在 Python 中将 3 个单独的 numpy 数组组合为 RGB 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10443295/

相关文章:

python - Pandas 数据框

Python GTK 拖放 - 获取 URL

python - 合并 ndarray 图像

c++ - 垂直翻转Char数组: is there a more efficient way?

ios - 使用 UIGraphicsImageRenderer 绘制图像时为什么要使用大量内存?

python - 未实现错误: Django doesn't provide a DB representation

python - 如何更改 Matplotlib 表的透明度/不透明性?

opencv - 如何计算IplImage的 “Arctan”和 “Pow”?

Android 如何将 Scalr 4.2 或 'java-image-scaling' 用于 HQ 缩略图

java - 用于从二进制文件在 Java 中构建图像(从拜耳滤波器传感器接收)的去马赛克算法