1

我是 python 新手,我正在尝试执行以下代码,但出现以下错误:

im[:,:,0] = f
ValueError: could not broadcast input array from shape (700,900,3) into shape (700,900)

有人可以帮我吗?

img = numpy.zeros((700, 900))

row_idx = 160
curve = []

count = 0
for i in range(0, 900):
                        contour.append((row_idx, i))


values, num_values = get_values(curve);


a = imread('20091016_seg1_26_18245948_1chop.png')
f = numpy.rot90(a, 2)
f = numpy.rot90(a, 2)

size_vec = numpy.shape(img)

im = numpy.zeros((size_vec[0],size_vec[1], 3));
im[:,:,0] = f
im[:,:,1] = f
im[:,:,2] = f


for i in range(0, num_values):
        im[values[i].y, values[i].x, 0] = 0.0
        im[values[i].y, values[i].x, 1] = 1.0
        im[values[i].y, values[i].x, 2] = 0.0

imsave('OUTPUT.png', im)

(删除的分号)

4

1 回答 1

1

它应该与:

im[..., 0] = f[..., 0]

问题是您试图将整体f放入im[..., 0]ValeError由于尺寸不兼容而给出。

于 2013-11-03T22:34:08.577 回答