So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image.
I tried 'Image' to do the job but it requires 'mode' to be attributed.
I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F' mode by default when Image.merge requires 'L' mode images to merge. If I would declare the attribute of array in fromarray() to 'L' at first place, all the R G B images become distorted.
But, if I save the images and then open them and then merge, it works fine. Image reads the image with 'L' mode.
Now I have two issues.
First, I dont think it is an elegant way of doing the work. So if anyone knows the better way of doing it, please tell
Secondly, Image.SAVE is not working properly. Following are the errors I face:
In [7]: Image.SAVE(imagefile

在Python中,用户遇到了将三个独立的numpy数组(R、G、B通道)合并成RGB图像的问题。尝试使用PIL库的`Image`,但发现需要指定'mode'。直接使用`Image.fromarray()`会默认设置为'F'模式,而`Image.merge`需要'L'模式。通过保存并重新打开图像可以解决模式问题,但认为这不是优雅的方法。同时,使用`Image.SAVE`保存图像时遇到TypeError。解决方案是将数组乘以256并将数据类型转换为'uint8',然后使用`Image.fromarray()`创建图像并保存。
最低0.47元/天 解锁文章
755

被折叠的 条评论
为什么被折叠?



