from fairdatanow import DataViewer, filters, login
import os
import re An image processing example
url = "https://laboppad.nl/falnama-project"dv = DataViewer(login(url), **filters(search='edited.tif', extensions=['.tif']))Connection with nextcloud server is ok.
Let’s take a look at the filenames.
im_files = dv.download_filtered()
titles = [re.sub('_Falnama.*', '', os.path.basename(f)) for f in im_files]Ready with downloading 28 selected remote files to local cache: /home/frank/.cache/fairdatanow
The holoviews way
Given these rather big files, we can use the awesome Python package holoviews to create an interactive visualization in a few lines of code in 15 seconds on my machine…
import imageio.v3 as iio
import holoviews as hv
from holoviews.operation.datashader import rasterize
import panel as pn
from pyvips import Imagepn.extension(sizing_mode='stretch_width')# Read the 28 super large tif files into arrays with pyvips
ims = [Image.new_from_file(im_file).numpy() for im_file in im_files]
# Convert into holoviews images
hv_images = [hv.Image(im) for im in ims]
# Rasterize to reduce size and speed up loading
rasterized_ims = [rasterize(hv_im, width=500, height=500) for hv_im in hv_images]
# Embed images in interactive viewer
image_panes = [pn.pane.HoloViews(raster_im.opts(xaxis=None, yaxis=None, cmap='gray', tools=['hover'], title=titles[i])) for i, raster_im in enumerate(rasterized_ims)]
# Create a grid
#xrays = pn.panel(pn.GridBox(*image_panes, ncols=6))
xrays = pn.GridBox(*image_panes, ncols=6)
xraysThis is quite nice. We might improve this code by soft coding the height and width of the thumbnails somehow.