import os
import shutil
from tiledb.bioimg import Converters, from_bioimg
from tiledb.bioimg.openslide import TileDBOpenSlide
= os.path.expanduser("~/tiledb-bioimg-chunked-ingestion")
root_dir
if os.path.exists(root_dir):
shutil.rmtree(root_dir)
os.makedirs(root_dir)
Chunked Ingestion of Biomedical Images
Biomedical images are often massive, making it sometimes impossible to load an entire image into memory for processing. Chunked ingestion breaks down these large images into smaller, manageable pieces called chunks. This enables efficient processing and offers the following benefits:
- Reduced memory footprint: Only the chunk being processed needs to live in memory.
- Parallel processing: Different chunks can be processed concurrently, speeding up computations.
- Efficient storage: Chunks can be stored and retrieved independently, optimizing data management.
TileDB offers chunked ingestion capabilities to all the supported formats. In this tutorial, you will learn how to enable chunked ingestion while ingesting different formats into TileDB.
The OpenSlideConverter
may not be 100% lossless with chunked=True
for levels greater than the highest resolution level, even though the converted images look visually identical to the original ones.
For chunked ingestion, you’ll follow similar steps as in the Biomedical Imaging Quickstart with only one slight change: the addition of an extra argument, chunked=True
.
Start by importing the required packages and creating the directory to hold the files used in this tutorial:
Next, fetch the image data and define your ingestion paths.
Now run the ingestion.
You can read the image data similarly to the Biomedical Imaging Quickstart.
Visualize the stored data with Pillow:
Clean up in the end by removing the data directory.
The TileDB converter streamlines biomedical image ingestion by automatically optimizing the process based on your available resources. It adjusts parameters behind the scenes to maximize performance, efficiently use resources, and minimize memory footprint, ensuring a smooth and efficient ingestion workflow.
TileDB ingestion
To ingest biomedical images with the TileDB API, include the same extra argument in your ingest function call. You can find a full tutorial on ingesting biomedical images into TileDB in the Biomedical Imaging Ingestion page.
This will ensure TileDB correctly processes and stores your changes.