首先,您需要carefully考虑您拥有的number of channels,以便可以创建一个有用的图像。在下面的例子中,我假设您有三个通道(红色、绿色和蓝色),可以组合成一个RGB图像。
import numpy as np
import cv2
"""Read each channel into a numpy array.
Of course your data set may not be images yet.
So just load them into three different numpy arrays as neccessary"""
a = cv2.imread('chanel_1.jpg', 0)
b = cv2.imread('chanel_2.jpg', 0)
c = cv2.imread('chanel_3.jpg', 0)
"""Create a blank image that has three channels
and the same number of pixels as your original input"""
needed_multi_channel_img = np.zeros((a.shape[0], a.shape[1], 3))
"""Add the channels to the needed image one by one"""
needed_multi_channel_img [:,:,0] = a
needed_multi_channel_img [:,:,1] = b
needed_multi_channel_img [:,:,2] = c
"""Save the needed multi channel image"""
cv2.imwrite('needed_multi_channel_img.png',needed_multi_channel_img)
合并是什么意思?它们都是灰度图像,所以它们在灰度颜色空间中基本上是相同的通道。当您尝试blend或add图像时,某些信息注定会丢失。使用OpenCV或枕头中的函数尝试以上两种方法。
当
OpenCV 3.x
将图像存储为numpy
数组时,只要图像的高度和宽度完全相同,我们就可以对每个图像进行平均并将它们相加。为了得到一个快速的结果,我手动编辑了四个图像的大小为
442(h) x 331(w)
像素。下面是合并的图像,有3个通道。
要合并11个图像,您可以将代码扩展为:
首先,您需要
carefully
考虑您拥有的number of channels
,以便可以创建一个有用的图像。在下面的例子中,我假设您有三个通道(红色、绿色和蓝色),可以组合成一个RGB图像。相关问题 更多 >
编程相关推荐