Hi Dash people,
I would like to select a tiff images from dropdown list of files (local computer) and display the selected file.
The image intensity will be adjusted before display
Here is the code:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import tifffile as tfi
import glob
import os
path_out = “/” # directory for saving image
image_directory = “/” input image path
list_of_images = [os.path.basename(x) for x in glob.glob(’{}*.tiff’.format(image_directory))]
def show_image_adjust(image, low_prec, up_prec):
“”"
image= np array 2d
low/up precentile border of the image
“”"
percentiles = np.percentile(image, (low_prec, up_prec))
scaled_ch1 = rescale_intensity(image, in_range=tuple(percentiles))
return scaled_ch1
app = dash.Dash()
app.layout = html.Div([
dcc.Dropdown(
id=‘image-dropdown’,
options=[{‘label’: i, ‘value’: i} for i in list_of_images],
value=list_of_images[0]
),
dcc.Slider(
id=‘my-slider_low_prec’,
min=1,
max=99,
step=5,
value=1,
),
dcc.Slider(
id=‘my-slider_up_prec’,
min=1,
max=99,
step=5,
value=99,
),
html.Img(id=‘image’,style={‘height’:‘10%’, ‘width’:‘10%’})
])
@app.callback(
Output(‘image’, ‘src’),
[Input(‘image-dropdown’, ‘value’)],
[Input(‘my-slider_low_prec’, ‘value’)],
[Input(‘my-slider_up_prec’, ‘value’)])
def update_image_src(dropdown,low,high):
pixels = tfi.imread(value)
im_pil=Image.fromarray(np.uint8(img))
os.chdir(path_out)
im_pil.save(“1.png”, format=‘png’)
img_name = “1.png”
return img_name
if name == ‘main’:
app.run_server()