Phython: как мне получить ошибку индекса в этом коде? Проблема "invalid index to scalar variable"
возникает в частях "the code of "# get brightness"
и "# stretch histogram"
этого кода. Как удалось решить эту проблему с недопустимым индексом для скалярной переменной?
def hist_stretch(img_buf, width, height, shift):
tmp1 = 0
tmp2 = 0
w_pHistBuf = np.zeros(256, dtype=np.uint32)
total = 0
ret_buf = np.zeros((width, height, 1),dtype=np.uint8)
# get brightness
for i in range(height):
for j in range(width):
total = total + img_buf[i][j][0]
w_pHistBuf[img_buf[i][j][0]] += 1
diff = (int)(shift - (total / (width * height)))
w_pHistBuf = np.zeros(256, dtype=np.uint32)
# move histogram
for i in range(height):
for j in range(width):
tmp = img_buf[i][j][0] + diff
if (tmp > 255):
tmp = 255
elif (tmp < 0):
tmp = 0
ret_buf[i][j][0] = tmp
w_pHistBuf[tmp] += 1
# stretch histogram
for i in range(256):
if (w_pHistBuf[i] != 0):
tmp1 = i
break
for i in range(255, 0, -1):
if (w_pHistBuf[i] != 0):
tmp2 = i
break
for i in range(height):
for j in range(width):
ret_buf[i][j][0] = (int)((255 * (ret_buf[i][j][0] - tmp1) / (tmp2 - tmp1)))
return ret_buf
for i in range(img_data.shape[0]):
img_tmp = hist_stretch(img_data[i], 160, 160, 128)
img_data[i] = img_tmp
for i in range(img_real.shape[0]):
img_tmp = hist_stretch(img_real[i], 160, 160, 128)
img_real[i] = img_tmp