Stitcher

This module contains the Stitcher class for handling image stitching operations.

For comprehensive information about the stitching process, including:

  • Position generation

  • Image assembly

  • Typical stitching workflows

  • Best practices for stitching

See the ImageStitchingStep class in the Steps documentation.

Stitcher

class ezstitcher.core.stitcher.Stitcher(config=None, filename_parser=None)

Class for handling image stitching operations.

Parameters:
  • config (StitcherConfig, optional) – Configuration for stitching

  • filename_parser (FilenameParser, optional) – Parser for microscopy filenames

generate_positions(image_dir, image_pattern, positions_path, grid_size_x, grid_size_y)

Generate positions for stitching using Ashlar.

Parameters:
  • image_dir (str or Path) – Directory containing images

  • image_pattern (str) – Pattern with ‘{iii}’ placeholder

  • positions_path (str or Path) – Path to save positions CSV

  • grid_size_x (int) – Number of tiles horizontally

  • grid_size_y (int) – Number of tiles vertically

Returns:

True if successful, False otherwise

Return type:

bool

assemble_image(positions_path, images_dir, output_path, override_names=None)

Assemble a stitched image using subpixel positions from a CSV file.

Parameters:
  • positions_path (str or Path) – Path to the CSV with subpixel positions

  • images_dir (str or Path) – Directory containing image tiles

  • output_path (str or Path) – Path to save final stitched image

  • override_names (list, optional) – Optional list of filenames to use instead of those in CSV

Returns:

True if successful, False otherwise

Return type:

bool

generate_positions_df(image_dir, image_pattern, positions, grid_size_x, grid_size_y)

Given an image_dir, an image_pattern (with ‘{iii}’ or similar placeholder) and a list of (x, y) tuples ‘positions’, build a DataFrame with lines like: file: <filename>; position: (x, y); grid: (col, row);

Parameters:
  • image_dir (str or Path) – Directory containing images

  • image_pattern (str) – Pattern with ‘{iii}’ placeholder

  • positions (list) – List of (x, y) positions

  • grid_size_x (int) – Number of tiles horizontally

  • grid_size_y (int) – Number of tiles vertically

Returns:

DataFrame with positions

Return type:

pandas.DataFrame

static parse_positions_csv(csv_path)

Parse a CSV file with lines of the form: file: <filename>; grid: (col, row); position: (x, y)

Parameters:

csv_path (str or Path) – Path to the CSV file

Returns:

List of (filename, x, y) tuples

Return type:

list

static save_positions_df(df, positions_path)

Save a positions DataFrame to CSV.

Parameters:
  • df (pandas.DataFrame) – DataFrame to save

  • positions_path (str or Path) – Path to save the CSV file

Returns:

True if successful, False otherwise

Return type:

bool

StitcherConfig

class ezstitcher.core.stitcher.StitcherConfig

Configuration for the Stitcher class.

tile_overlap: float = 10.0

Percentage overlap between tiles.

max_shift: int = 50

Maximum allowed shift in pixels.

margin_ratio: float = 0.1

Ratio of image size to use as margin for blending.

pixel_size: float = 1.0

Pixel size in micrometers.