Skip to content
Snippets Groups Projects
Commit e8649b9f authored by Christian Kento Rasmussen's avatar Christian Kento Rasmussen
Browse files

Add uniform image generation for Gradio plots to prevent flickering

parent 503d7368
No related branches found
No related tags found
1 merge request!142Gradio plot flicker fix
This commit is part of merge request !142. Comments created here will be created in the context of that merge request.
......@@ -163,17 +163,31 @@ class Interface(BaseInterface):
# Visualization and results
with gr.Row():
def create_uniform_image(intensity=1):
"""
Generates a blank image with a single color.
Gradio `gr.Plot` components will flicker if there is no default value.
bug fix on gradio version 4.44.0
"""
pixels = np.zeros((100, 100, 3), dtype=np.uint8) + int(intensity * 255)
fig, ax = plt.subplots(figsize=(10, 10))
ax.imshow(pixels, interpolation="nearest")
# Adjustments
ax.axis("off")
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
return fig
# Z Slicer
with gr.Column(visible=False) as result_z_slicer:
zslice_plot = gr.Plot(label="Z slice")
zslice_plot = gr.Plot(label="Z slice", value=create_uniform_image(1))
zpos = gr.Slider(
minimum=0, maximum=1, value=0.5, step=0.01, label="Z position"
)
# Y Slicer
with gr.Column(visible=False) as result_y_slicer:
yslice_plot = gr.Plot(label="Y slice")
yslice_plot = gr.Plot(label="Y slice", value=create_uniform_image(1))
ypos = gr.Slider(
minimum=0, maximum=1, value=0.5, step=0.01, label="Y position"
......@@ -181,7 +195,7 @@ class Interface(BaseInterface):
# X Slicer
with gr.Column(visible=False) as result_x_slicer:
xslice_plot = gr.Plot(label="X slice")
xslice_plot = gr.Plot(label="X slice", value=create_uniform_image(1))
xpos = gr.Slider(
minimum=0, maximum=1, value=0.5, step=0.01, label="X position"
......@@ -439,6 +453,7 @@ class Interface(BaseInterface):
def update_slice_wrapper(self, letter):
def update_slice(position_slider:float, cmap:str):
print('update slice')
"""
position_slider: float from gradio slider, saying which relative slice we want to see
cmap: string gradio drop down menu, saying what cmap we want to use for display
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment