from fairdatanow import RemoteData
import os
import re
An image processing example
One step at a time
In the previous section we found and downloaded 28 tif files that we need to inspect and subsequently process. In this example for every imaged page of the falnama manuscript we need to stitch the upper and lower halves of the pages.
= {
configuration 'url': "https://laboppad.nl/falnama-project",
'user': os.getenv('NC_AUTH_USER'),
'password': os.getenv('NC_AUTH_PASS')
}
= RemoteData(configuration)
remote_data ='edited.tif') remote_data.listdir(search_regex
Please wait while scanning all file paths in remote folder...
Ready building file table for 'falnama-project'
Total number of files and directories: 6342
Total size of the files: 194.8 GiB
Let’s take a look at the filenames.
= remote_data.download_selected()
im_files = [re.sub('_Falnama.*', '', os.path.basename(f)) for f in im_files] titles
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
='stretch_width') pn.extension(sizing_mode
# Read the 28 tif files into arrays
= [iio.imread(im_file) for im_file in im_files]
ims
# Convert into holoviews images
= [hv.Image(im) for im in ims]
hv_images
# Rasterize to reduce size and speed up loading
= [rasterize(hv_im, width=500, height=500) for hv_im in hv_images]
rasterized_ims
# Embed images in interactive viewer
= [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)] image_panes
# Create a grid
#xrays = pn.panel(pn.GridBox(*image_panes, ncols=6))
= pn.GridBox(*image_panes, ncols=6)
xrays
xrays
This is quite nice. We might improve this code by soft coding the height and width of the thumbnails somehow.