fairdatanow
  1. An image processing example
  • Welcome to fairdatanow
  • Getting started with Python
  • Exploring your remote data in a breeze
  • Exploring your remote data with tabulator
  • An image processing example
  • iframes

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.

from fairdatanow import RemoteData
import os 
import re
configuration = {
    'url': "https://laboppad.nl/falnama-project", 
    'user':    os.getenv('NC_AUTH_USER'),
    'password': os.getenv('NC_AUTH_PASS')
}
remote_data = RemoteData(configuration)
remote_data.listdir(search_regex='edited.tif')
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.

im_files = remote_data.download_selected()
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
hv.extension('bokeh')
ⓘ
pn.extension(sizing_mode='stretch_width')
# Read the 28 tif files into arrays 
ims = [iio.imread(im_file) 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)

xrays

This is quite nice. We might improve this code by soft coding the height and width of the thumbnails somehow.

Exploring your remote data with tabulator
 

2025 Rijkserfgoedlaboratorium Amsterdam | Made with nbdev

  • Report an issue