我想将RGB通道合并到我用之前定义的r、g、b值归一化每个通道后创建的函数中,公式为
def color_norm(image_norm):
pixels = np.array(image_norm)
ar_mean = np.mean(pixels, axis=(0,1))
(H,W) = image_norm.shape[:2]
for x in range(H):
for y in range(W):
Ri = image_norm[:,:,0]
Gi = image_norm[:,:,1]
Bi = image_norm[:,:,2]
R = Ri[x,y] = np.min((Ri[x,y]/(ar_mean[0]))*(r))
if R > 255:
# saturate value
R = 255
else:
# add normally
R = R
G = Gi[x,y] = np.min((Gi[x,y]/(ar_mean[1]))*(g))
if G > 255:
# saturate value
G = 255
else:
# add normally
G = G
B = Bi[x,y] = np.min((Bi[x,y]/(ar_mean[2]))*(b))
if B > 255:
# saturate value
B = 255
else:
# add normally
B = B
image_norm[x,y] = [R,G,B]
当我在单个图像中尝试时,它工作,但当我将此函数传递给数据集(包含5个图像)时,它引发错误TypeError: Image data of dtype object cannot be converted to float
有人知道如何合并RGB通道,以便我可以传递此函数吗?
2条答案
按热度按时间bxgwgixi1#
这里有一个完整的代码
3mpgtkmj2#
根据我试过的代码,这里有一个解决你问题的方法。
它返回的结果如下所示。