我认为当我从numpy v1.11转到v1.12时出现了此错误
原始代码从Matlab转换为Python,当我从numpy v1.11转到v1.12时,我认为此错误体现了
原始代码已从Matlab转换为Python,并且有些转换为浮点数与整数索引错误 显然不支持FP。 如果那是错误-应该在哪里进行更改
我的错误消息
outline_mask = get_outline_mask(mask_str, image.shape[0], image.shape[1])
File "/var/www/html/code_drop/dicomutils/utils.py", line 136, in get_outline_mask
img[(list(y), list(x))] = 1
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
我的代码段是
def get_outline_mask(p, rows, cols): # Get outline mask of the marked area
p2 = p.replace('(', '[').replace(')',']')
xy = json.loads('[' + p2 + ']')
# Subtract 1 because python is 0-based
xy = np.array(xy).astype('float').round() - 1
# Limit to image region
x = xy[:, 0].clip(0, cols - B1)
y = xy[:, 1].clip(0, rows - 1)
# close the loop
x = np.r_[x, x[0]]
y = np.r_[y, y[0]]
# Missing points
x_add = []
y_add = []
for i in xrange(len(x) - 1):
if get_distance(x[i], y[i], x[i + 1], y[i + 1]) > 1.4142:
line = get_line(x[i], y[i], x[i + 1], y[i + 1])
if len(line) > 2:
line_x = map(lambda z: z[0], line)[1:-1]
line_y = map(lambda z: z[1], line)[1:-1]
x_add += line_x
y_add += linee