Skip to main content

Tools for image registration between multiplexed and HnE stained tissue images

Project description

stainwarpy

Stainwarpy Logo

Docker PyPI version

stainwarpy is a command-line tool and a Python package for registering H&E stained and multiplexed tissue images. It provides a feature based registration pipeline, saving registered images, transformation maps and evaluation metrics.

Features

  • Register H&E images and multiplexed images (after extracting DAPI channel) using transformations.
  • Supports feature-based registration.
  • Outputs registered images (in the pixel size of moving image), transformation maps and evaluation metrics (TRE and Mutual Information).
  • Transforms segmentation masks based on the computed transformations

Recommendations

  • For most cases, it is recommended to register H&E images onto multiplexed images (H&E as moving image).
  • The default similarity transformation usually works well and stable, therefore recommended.

Installation

You can install stainwarpy using pip:

pip install stainwarpy

Usage as a command-line tool

Register Images

stainwarpy register <fixed_path> <moving_path> <output_folder> <fixed_img> [options]

Examples:

stainwarpy register data/fixed_img.ome.tiff data/moving_img.ome.tiff ../output multiplexed
stainwarpy register data/fixed_img.tif data/moving_img.tif ../output multiplexed --fixed-px-sz 0.21 --moving-px-sz 0.52

Arguments:

  • fixed_path: Path to the fixed image (H&E or DAPI or Multiplexed image path (.tif/.tiff./.ome.tif/.ome.tiff))
  • moving_path: Path to the moving image (H&E or DAPI or Multiplexed image path (.tif/.tiff./.ome.tif/.ome.tiff))
  • output_folder: Folder to save the registered images and metrics
  • fixed_img: Type of fixed image: multiplexed or hne

Options:

  • --fixed-px-sz : Pixel size of the fixed image (no need to provide for ome.tiff, so default: None)
  • --moving-px-sz : Pixel size of the moving image (no need to provide for ome.tiff, so default: None)
  • --feature-tform : Feature transformation method: similarity oraffine or projective (default: similarity)

Output

After running registration, the following files/folders will be generated and saved in the specified output folder:

  • registration_metrics.json — TRE and Mutual Information
  • 0_final_channel_image.ome.tif — Registered image (in the pixel size of moving image)
  • feature_based_transformation_map.npy — Transformation map

Extract a Channel (DAPI can be extracted for registration)

stainwarpy extract-channel <file_path> <output_folder_path> [--channel-idx N]

Arguments

  • file-path : Path to multichannel image (.tif/.tiff/.ome.tif/.ome.tiff)
  • output-folder-path : Folder to save the extracted channel image

Options

  • --channel-idx: Channel index to extract (default: 0 for DAPI)

Output

  • multiplexed_channel_{channel_idx}.tif - Image with the extracted channel saved in the specified output folder

Transform segmentation Masks

Transform segmentation masks based on the transformation maps produced with the command register.

stainwarpy transform-seg-mask <mask_path> <fixed_path> <output_folder_path> <tform_map_path> <moving_px_sz> [--fixed-px-sz]

Arguments

  • mask_path : Path to the segmentation mask of the moving image (.npy)
  • fixed_path : Path to the fixed image (.tif/.tiff/.ome.tif/.ome.tiff)
  • output_folder_path : Folder to save the transformed segmentation mask
  • tform_map_path : Path to the transformation map
  • moving_px_sz : Path to moving image if .ome.tiff or Pixel size of the moving image

Options

  • --fixed-px-sz : Pixel size of the fixed image (no need to provide for ome.tiff, so default: None)

Output

  • transformed_segmentation_mask.npy : The segmentation mask transformed to the fixed image coordinate space saved in the specified output folder

Usage as a Python Library

Although stainwarpy is mainly a command-line tool, its functions can also be used directly in Python for scripting.

Example: Running the Registration Pipeline

from stainwarpy.regPipeline import registration_pipeline

# run registration pipeline
tform_map, final_img, tre, mi = registration_pipeline(
    fixed_path="fixed_image.tif",
    moving_path="moving_image.tif",
    fixed_px_sz=0.5,
    moving_px_sz=0.5,
    fixed_img="multiplexed",
    feature_tform="affine"        # to use a transformation other than default "similarity"
)

print("TRE:", tre)
print("Mutual Information:", mi)

License

This project is licensed under the MIT License.

This project includes portions of code in stainwarpy/preprocess.py adapted from HistomicsTK (https://github.com/DigitalSlideArchive/HistomicsTK/), which is licensed under Apache License 2.0. See LICENSE_HISTOMICSTK.txt for the full license text.

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

stainwarpy-0.1.7.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

stainwarpy-0.1.7-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file stainwarpy-0.1.7.tar.gz.

File metadata

  • Download URL: stainwarpy-0.1.7.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for stainwarpy-0.1.7.tar.gz
Algorithm Hash digest
SHA256 98edd1b0d5c97abb9994c18de3430a1d1018050a42f1a3e77f06763678e7b0f5
MD5 498380c168b0a4744fdb61a54b18218b
BLAKE2b-256 9baef81e9b95857d29e5bd615840dd40dd59a9db3fb830f86bc3143bdd498ce0

See more details on using hashes here.

File details

Details for the file stainwarpy-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: stainwarpy-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for stainwarpy-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bea05ad0f8c7c8e1738b55b70e8e1f9d6e836e918ef78a0fa8689fc8e5955c10
MD5 93e508ad50d2f0a691d7a4be64a1b4ff
BLAKE2b-256 72383a79d9341dcccefb14e5cb0f24638a91b85c69c1844b98ec1c9dd229169c

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