Skip to main content

Stitch SEM tile images using stage coordinates from metadata files

Project description


title: Sem Stitcher emoji: 🏢 colorFrom: blue colorTo: yellow sdk: gradio sdk_version: 6.4.0 app_file: app.py pinned: false license: mit short_description: Mosaic JEOL SEM or microprobe images and add analysis points

🔬 SEM Stitcher

Stitch scanning electron microscope (SEM) tile images using stage coordinates from metadata files.

Hugging Face Space PyPI License: MIT

Features

  • Stitch SEM tiles using stage coordinates from metadata files
  • Overlay analysis points from CSV files
  • Web interface via Hugging Face Spaces (no coding required)
  • Python library for integration into workflows
  • 🖥Command-line tool for batch processing

Currently supports JEOL metadata format.

Quick Start

Web Interface (No Installation)

Visit the Hugging Face Space to use the web interface.

Python Library

pip install semstitcher
from semstitcher import stitch_tiles

# Basic stitching
mosaic, transform = stitch_tiles("path/to/tiles", output_path="mosaic.tif")

# With point overlay
mosaic, transform = stitch_tiles(
    "path/to/tiles",
    output_path="mosaic.tif",
    csv_path="analysis_points.csv"
)

Command Line

# Basic stitching
semstitcher /path/to/tiles output.tif

# With point overlay
semstitcher /path/to/tiles output.tif --csv points.csv

File Format Requirements

Image and Metadata Files

  • Images: .tif or .tiff files
  • Metadata: .txt files with the same base name as the image
    • Example: sample_001.tif and sample_001.txt

JEOL Metadata Format

The metadata file must contain at minimum:

$CM_STAGE_POS -2.4153 10.1840 10.7170 0 0 0
$$SM_MICRON_BAR 170
$CM_FULL_SIZE 5120 3840

CSV Format for Analysis Points

Phase,Point,X-POS,Y-POS
Olivine,1,-2.5607,11.7652
Spinel,1,-3.1858,10.2133
Cpx,1,-3.2824,11.8894

Required columns: X-POS, Y-POS
Optional columns for labels: Phase, Point

API Reference

stitch_tiles()

High-level function to stitch tiles and optionally overlay points.

from semstitcher import stitch_tiles

mosaic, transform = stitch_tiles(
    input_dir="path/to/tiles",      # Directory with .tif and .txt files
    output_path="output.tif",        # Output file path (optional)
    csv_path="points.csv",           # CSV with analysis points (optional)
    point_radius=25,                 # Radius of point markers
    compression='lzw',               # TIFF compression
)

create_mosaic()

Lower-level function for more control.

from semstitcher import create_mosaic
from semstitcher.stitcher import load_tiles_from_directory

tiles = load_tiles_from_directory("path/to/tiles")
mosaic, transform = create_mosaic(tiles)

overlay_points()

Add point markers to an existing mosaic.

from semstitcher import overlay_points

mosaic = overlay_points(
    mosaic,
    transform,
    csv_path="points.csv",
    point_radius=25,
    point_color=(255, 105, 180),  # Pink
    text_color=(255, 255, 0),     # Yellow
)

Coordinate System

This tool is designed for JEOL SEMs where:

  • Stage X increases to the left in the image
  • Stage Y increases downward in the image

The coordinate transformation is applied automatically.

Development

# Clone the repository
git clone https://github.com/yourusername/sem-stitcher.git
cd sem-stitcher

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Run the Gradio app locally
python app.py

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Planned Features

  • Support for FEI/Thermo Fisher metadata format
  • Support for Zeiss metadata format
  • Automatic tile alignment using image features
  • Blend overlapping regions
  • Export to pyramidal TIFF for large mosaics

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semstitcher-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semstitcher-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file semstitcher-0.1.0.tar.gz.

File metadata

  • Download URL: semstitcher-0.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for semstitcher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b49fab1ec55789172bb489fdf12fa64ff71d8d555510a65fa5a241854be52258
MD5 5dcb5dbdebdf25c5a33e1da8d05443f4
BLAKE2b-256 6056b93f33d8dee5acf3b3dcaa22048dc34f70ab7fde73f18c871400db77e2c4

See more details on using hashes here.

File details

Details for the file semstitcher-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: semstitcher-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for semstitcher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 706106db8df394026e3c5a8cad5ef58f1695c4052f67077f7c3d99cdfb2c987a
MD5 995b6e06fa2645f6888f2a1f4537c4c5
BLAKE2b-256 bcbb3075c58d6a865397a1ef2e53c3c823b455044579a94b1b991f486a8a1cfe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page