Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
806 views
in Technique[技术] by (71.8m points)

displaying images in a for loop in python

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...