This directory contains examples demonstrating the FIM (FastImage) library's capabilities.
A minimal example showing the complete workflow requested:
- Load image with fastslide
- Print metadata
- Crop the center
- Rescale with MagicKernel2021
- Convert to PIL Image
Usage:
python simple_resize_example.py slide.svsOutput:
- Prints slide dimensions and metadata
- Saves
output.pngwith the processed result
A comprehensive example demonstrating:
- Loading whole slide images with fastslide integration
- Metadata extraction and display
- Center cropping
- High-quality resizing with different kernels
- Subpixel-accurate box parameter usage
- Kernel comparison (Lanczos2 vs Lanczos3 vs Magic2021)
- Converting to PIL Image for further processing
Usage:
python python_resize_example.py slide.svs 512
python python_resize_example.py slide.mrxs 1024Outputs:
output_512x512.png- Main resultoutput_with_box.png- Subpixel box exampleoutput_lanczos2_(fastest).png- Lanczos2 kernel resultoutput_lanczos3_(default).png- Lanczos3 kernel resultoutput_magic2021_(highest_quality).png- Magic2021 kernel result
All FIM operations are lazy - they build a computation graph but don't execute until you:
- Call
.to_numpy()to convert to NumPy array - Call
.write_png()or.write_tiff()to save to file
This allows efficient processing of large images by only computing what's needed.
- LANCZOS2: Fastest, radius 2, good quality
- LANCZOS3: Default, radius 3, excellent quality/speed balance
- MAGIC2021: Highest quality, radius 4.5, minimal ringing artifacts
The Box class allows specifying source regions with floating-point pixel coordinates:
box = fim.Box(x1=10.5, y1=20.5, x2=510.5, y2=520.5)This is useful for:
- Subpixel shifts (like MRXS tile alignment)
- Precise region extraction combined with scaling
- Avoiding rounding errors in coordinate transformations
pip install numpy pillowIf you've built FIM with Bazel, the Python bindings are available in the workspace:
# Build the Python bindings
bazelisk build //aifo/fimage/python:fim
# Run tests to verify installation
bazelisk test //aifo/fimage/src/python:resize_test
# Run the example
python3 examples/simple_resize_example.py /path/to/slide.svs