图像分割中索引错误太多

问题描述

我正在尝试破解如何解决我的代码中出现错误的原因。

基本上,我有一个 JPG 图像,我需要通过使用三个 RGB 通道上的阈值对其进行分割。

这是我的代码

img = cv2.imread('sample.jpg')
img = np.asarray(img)
img = img[:,:,0:3]
plt.imshow(img)
plt.show()

img_gray = rgb2gray(img)
img_gray = np.around(img_gray)
img_gray = img_gray.astype(int)
img_gray

histogram2,bins2 = np.histogram(img_gray,bins=range(255))
plt.bar(bins2[1:],histogram2)
plt.show()

img_select = np.where((img_gray[:,0]<150) & (img_gray[:,1]>70) & (img_gray[:,2]<90),1,0)
plt.imshow(img_select,cmap = 'gray')
plt.show()

错误在 img_select 部分。我收到了这个错误

“数组索引过多”

有人可以帮我解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)