您可以使用两个 for 循环来执行此操作。我面临着同样的问题。
for i, val in enumerate(images_gray):
ret,thresh1 = cv2.threshold(images_gray[i],110,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(images_gray[i],70,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(images_gray[i],127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(images_gray[i],77,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(images_gray[i],127,255,cv2.THRESH_TOZERO_INV)
titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [images_gray[i], thresh1, thresh2, thresh3, thresh4, thresh5]
for k in range(6):
plt.rcParams["figure.figsize"] = (20,10)
plt.subplot(45,6,k+1),plt.imshow(images_gray[i],'gray', vmin=0,vmax=255)
plt.title(titles[k])
k+=1
plt.xticks([]),plt.yticks([])
plt.show()
i+=1
我使用了 45 张图片。并想展示一个 6 阈值比较。