3D Image Analysis with qim3d

Felipe Delestro
fima@dtu.dk

QIM Center

Center for Quantification of Imaging Data from MAX IV

supported by

Rebecca
Engberg

Center Manager

Anders Bjorholm Dahl

Head of the QIM Center

Jon
Sporring

Deputy Head of the QIM Center

an open-source Python library, that focuses on 3D volumetric data

Getting started is easy:
pip install qim3d

Full documentation at https://platform.qim.dk/qim3d/

import qim3d

vol = qim3d.io.load("path/to/image.tif", virtual_stack=True)

Supported formats:

  • Tiff (including file stacks)
  • HDF5
  • TXRM/TXM/XRM
  • NIfTI
  • PIL (including file stacks)
  • VOL/VGI
  • DICOM
qim3d.io.save("my_file.h5", vol)
import qim3d

vol = qim3d.examples.bone_128x128x128

blobs_256x256x256

bone_128x128x128

cement_128x128x128 

fly_150x256x256

NT_128x128x128

shell_225x128x128

import qim3d

# Get data
vol = qim3d.examples.cement_128x128x128
vol_blurred = qim3d.processing.gaussian(vol, sigma=2)

# Detect blobs, and get binary mask
blobs, mask = qim3d.processing.blob_detection(
    vol_blurred,
    min_sigma=1,
    max_sigma=8,
    threshold=0.001,
    overlap=0.1,
    background="bright"
    )

# Visualize detected blobs
qim3d.viz.circles(blobs, vol, alpha=0.8, color='blue')
import qim3d

vol = qim3d.examples.cement_128x128x128
binary = qim3d.processing.filters.gaussian(vol, 2)<60

qim3d.viz.slices(binary, axis=1)
labeled_volume, num_labels = qim3d.processing.operations.watershed(binary)

cmap = qim3d.viz.colormaps.objects(num_labels)
qim3d.viz.slices(labeled_volume, axis=1, cmap=cmap)
cmap = qim3d.viz.colormaps.objects(num_labels, style='bright', min_dist=0.5)
import qim3d

vol = qim3d.examples.cement_128x128x128[50:150]
vol_bin = vol<80

cc = qim3d.processing.get_3d_cc(vol_bin)
qim3d.viz.plot_cc(cc, crop=True, show=True, overlay=None, n_slices=5, component_indexs=[4])
qim3d.viz.plot_cc(cc, crop=True, show=True, overlay=vol, n_slices=5, component_indexs=[4])
import qim3d

vol = qim3d.examples.cement_128x128x128
qim3d.viz.slices(vol, vmin=0, vmax=255)
vol_filtered  = qim3d.processing.operations.remove_background(vol,
                                                      min_object_radius=3, 
                                                      background="bright")
qim3d.viz.slices(vol_filtered, vmin=0, vmax=255)
import qim3d

vol = qim3d.examples.cement_128x128x128
qim3d.viz.interactive_fade_mask(vol)
import qim3d



qim3d.viz.vol(vol)
import qim3d
vol_faded = qim3d.processing.operations.edge_fade(vol, decay_rate=4, 
                                                  ratio=0.45, 
                                                  geometric='cylindrical')
qim3d.viz.vol(vol_faded)
import qim3d
vol = qim3d.utils.generate_volume(noise_scale=0.05, threshold=0.4)
qim3d.viz.vol(vol)
import qim3d

vol = qim3d.examples.NT_128x128x128
val, vec = qim3d.processing.structure_tensor(vol, visualize=True, axis=2)
import qim3d

fly = qim3d.examples.fly_150x256x256
lt_fly = qim3d.processing.local_thickness(fly, visualize=True, axis=0)
qim3d gui --data-explorer

qim3d gui --local-thickness

Next steps of development

  • Simplify dependencies
  • Operations for large volumetric data (using Dask and Zarr)
  • Pre-trained DL models
  • GUI for volumetric reconstruction (Using CIL)
  • GUI for volumetric data annotation
Author Commits First commit
Felipe Delestro 170 2023-05-12
Stefan Engelmann Jensen 29 2023-06-29
Oskar Kristoffersen 15 2023-07-05
Christian Kento Rasmussen 19 2024-02-01
Alessia Saccardo 7 2024-02-19
David Grundfest 4 2024-04-12
Anna Bøgevang Ekner 3 2024-04-18

Thanks to all that contributed with code for qim3d!