这是我的代码:
img = imread("lena.jpg")
for channel in range(3):
res = filter(img[:,:,channel], filter)
# todo: stack to 3d here
如您所见,我正在为图片中的每个通道应用一些过滤器。如何将它们堆叠回3D阵列? (=原始图像形状)
谢谢
答案 0 :(得分:1)
您可以使用np.dstack:
import numpy as np
image = np.random.randint(100, size=(100, 100, 3))
r, g, b = image[:, :, 0], image[:, :, 1], image[:, :, 2]
result = np.dstack((r, g, b))
print("image shape", image.shape)
print("result shape", result.shape)
输出
image shape (100, 100, 3)
result shape (100, 100, 3)
答案 1 :(得分:1)
我之前用所需的形状初始化了一个变量
img = imread("lena.jpg")
res = np.zeros_like(img) # or simply np.copy(img)
for channel in range(3):
res[:, :, channel] = filter(img[:,:,channel], filter)