IndexError:索引 245 超出尺寸为 245 的轴 1

问题描述 投票:0回答:1

我想改变h值,但是遇到错误:

---> 42             h = (((image1[y,x,c] - 75) * 180) / 180) + 0
     43 #             print (image1[y,x,c])
     45 image1[:,:,0] = h

IndexError: index 245 is out of bounds for axis 1 with size 245

我的密码是:

for x in range (image1.shape[0]):
    for y in range(image1.shape[1]):
        for c in range(image1.shape[2]):
#             h = (((image1[:,:,0] - OldMin) * NewRange) / OldRange) + NewMin
            h = (((image1[y,x,c] - 75) * 180) / 180) + 0
#             print (image1[y,x,c])

image1[:,:,0] = h
image1[:,:,1] = 255
image1[:,:,2] = 255
image2 = cv2.cvtColor(image1, cv2.COLOR_HSV2BGR)

请帮助我。谢谢。

python indexoutofboundsexception index-error
1个回答
0
投票
for x in range (image1.shape[0]):
    for y in range(image1.shape[1]):
        for c in range(image1.shape[2]):

您正在使用

x
循环第一维度,
y
循环第二维度,
c
循环第三维度。

h = (((image1[y,x,c] - 75) * 180) / 180) + 0

...但是您使用

y
作为第一个维度索引,而
x
作为第二个维度索引。

你为什么要那样做?

使用

image1[x,y,c]
代替。

© www.soinside.com 2019 - 2024. All rights reserved.