I am trying to create and display pictures in a for loop but only picture for the last loop is displayed.
lst=[2, 4, 6, 8, 16]. In each iteration, j picks a number from lst and runs bunch of functions and then it forms an image. Here, I would like to display all the images for lst values but only the image for lst=16 is printed out. Is there any way I can have the image in each iteration displayed?
#Reshape back to pixel form
def reshape_image(arr):
arr = arr.astype(dtype='uint8')
img = Image.fromarray(arr, 'RGB')
return imshow(np.asarray(img))
for j in lst:
labels=kmeans(X, j, max_steps=np.inf)
ind = np.column_stack((img_reshaped, labels))
centers = {}
for i in set(labels):
c = ind[ind[:,3] == i].mean(axis=0)
centers[i] = c[:3]
img_clustered = np.array([centers[i] for i in labels])
r, c, l = img.shape
img_disp = np.reshape(img_clustered, (r, c, l), order="C")
reshape_image(img_disp)
question from:
https://stackoverflow.com/questions/65838985/displaying-images-in-a-for-loop-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…