Skip to main content

Convienent handling of annotated whole slide images

Project description

WSI_handling

Code for handling digital pathology pyramidal whole slide images (WSIs). Currently works with annotation XMLs from Aperio ImageScope or annotation json's from QuPath and image formats supported by Openslide.

Supports getting a tile from a WSI at the desired micron-per-pixel (mpp), getting either the whole WSI or an annotated region, generating a mask image for either a tile or the WSIs, and showing the location of a tile on the WSI.

Annotation format

Example annotations are provided in ./example_annotations

XML annotations must follow the AperioImagescope format:

<?xml version="1.0" encoding="UTF-8"?>
<Annotations>
<Annotation LineColor="65280">
<Regions>
<Region>
<Vertices>
<Vertex X="56657.4765625" Y="78147.3984375"/>
<Vertex X="56657.4765625" Y="78147.3984375"/>
<Vertex X="56664.46875" Y="78147.3984375"/>
</Region>
</Regions>
</Annotation>
</Annotations>

With more <Annotation> or <Region> blocks for additional annotations.

json annotations must follow QuPath's json export format:

[
  {
    "type": "Feature",
    "id": "PathAnnotationObject",
    "geometry": {
      "type": "Polygon",
      "coordinates": [
        [
          [76793.51, 4613.02],
          [76651.56, 4684],
          [76580.59, 4684],
          [76580.59, 4754.97]                   
        ]
      ]
    },
    "properties": {
      "classification": {
        "name": "Tumor",
        "colorRGB": -3670016
      },
      "isLocked": true,
      "measurements": []
    }
]

Installation

pip install WSI_handling

Usage

import matplotlib.pyplot as plt
from WSI_handling import wsi
img_fname=r'/mnt/ccipd_data/TCGA_PRAD/2018Jan14/TCGA-EJ-5519-01Z-00-DX1.svs'
xml_fname=r'./example_annotations/TCGA-EJ-5519-01Z-00-DX1.xml'
w = wsi(img_fname,xml_fname)
plt.imshow(w.get_wsi(desired_mpp=8));

png

plt.imshow(w.mask_out_annotation(desired_mpp=8));

png

plt.imshow(w.get_annotated_region(desired_mpp=2,colors_to_use='other',annotation_idx='largest')[0]);

png

plt.imshow(w.get_annotated_region(desired_mpp=2,colors_to_use='red',annotation_idx='largest')[0]);

png

img, mask = w.get_annotated_region(desired_mpp=8,colors_to_use='green',annotation_idx='largest',mask_out_roi=False)
plt.imshow(img);
plt.show()
plt.figure
plt.imshow(mask);

png

png

plt.imshow(w.get_tile(desired_mpp=1,coords=(3400,54000),wh=(2000,2000)));

png

plt.imshow(w.mask_out_tile(desired_mpp=1,coords=(3400,54000),wh=(2000,2000)));

png

plt.imshow(w.show_tile_location(desired_mpp=1,coords=(3400,54000),wh=(2000,2000)));

png

img_fname=r'/mnt/ccipd_data/TCGA_PRAD/2018Jan14/TCGA-EJ-5519-01Z-00-DX1.svs'
xml_fname=r'./example_annotations/TCGA-EJ-5519-01Z-00-DX1.json'
w = wsi(img_fname,xml_fname)
plt.imshow(w.mask_out_annotation(desired_mpp=8,colors_to_use=['tumor','other']));

png

plt.imshow(w.get_annotated_region(desired_mpp=2,colors_to_use=['tumor'],annotation_idx='largest')[0]);

png

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

WSI_handling-0.16.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file WSI_handling-0.16.2-py3-none-any.whl.

File metadata

  • Download URL: WSI_handling-0.16.2-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for WSI_handling-0.16.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad053481970823c39be70fd9eee77e4ed6ac666da107d605b3b108392ff6072f
MD5 7a45c5cd1dd270ea7c77e0fb9c7dc215
BLAKE2b-256 d8f2936462bc6f6a6800663b81f9bda55da25b64b11dfe3377f0815057564ee7

See more details on using hashes here.

Supported by

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