'How to display multiple images with sliders at once?
so I have 10 images. For each image, I have 2 sliders. I would like to display all 10 images, each with the 2 sliders. Then, after adjusting the sliders for all the images, I would like to save the slider information for each image (since this updated information will be used later on).
This is what my code looks like for ONE image. I would post all the variables/info needed but the code would be unable to run without the trained ML model (gen_mdl), which is used to generate the images but I cannot upload it. The "store" list contains numbers that represent each image (e.g. store[0]= "1" for image 1 or store1= "53" for image 53). So, in the code below, store[0] = "1", the number that represents image 1, which I use to pull the information from image 1 in a separate dataframe. So, I'd have to be iterating through "store" to iterate through each of the first 10 images.
Again, I would like to display all 10 images at once with their respective sliders. Then, after adjusting all 10 images' sliders, I would like to save the information from each slider (in the code below, which is just for one image, the information I'd like to save is in an array called "noise")
%matplotlib notebook
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt
r,c=1,1
latent_dim = 8
cond_dim = 8
vfs = 0.3*np.ones((r*c,cond_dim))
noise=np.array(lv_df.iloc[store[0],0:8]) #information related to image # 1, represented by store[0]
gen_imgs = gen_mdl.predict([noise,vfs])
gen_imgs = 0.5 * gen_imgs + 0.5
original_img=255-(gen_imgs[0,:,:,0]*255)
fig = plt.figure(figsize=(4,2))
ax = fig.add_subplot(1, 1, 1)
line = ax.imshow(original_img, cmap='gray')
plt.axis('off')
def update(lv_1=[0][0], lv_2=noise[0][1], lv_3=noise[0][2], lv_4=noise[0][3]):
noise[0][0]=lv_1
noise[0][1]=lv_2
noise[0][2]=lv_3
noise[0][3]=lv_4
gen_imgs = gen_mdl.predict([noise,vfs])
gen_imgs = 0.5 * gen_imgs + 0.5
updated_img=255-(gen_imgs[0,:,:,0]*255)
line.set_data(updated_img)
fig.canvas.draw()
s_range=(-1.0,1.0,0.05)
interact(update,lv_1=s_range, lv_2=s_range, lv_3=s_range,lv_4=s_range)
This is what the code above displays (just one image & its respective slider). I would like 10 of these (different images/slider information) to be displayed at once. Then, I'd like to adjust all the sliders and once I'm done, save the slider information in an array or separate arrays for use later.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|