Skip to content

dimi-lab/TIL-SIL-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”¬ TIL and SIL Count in Ovarian Whole Slide Image

This Jupyter Notebook performs a detailed analysis of cell segmentation and classification data from an Ovarian Whole Slide Image (WSI). The core function is to categorize regions (patches) of the WSI as Tumor or Stroma and then quantify the associated lymphocyte infiltration, resulting in the calculation of Tumor Infiltrating Lymphocytes (TIL) and Stromal Infiltrating Lymphocytes (SIL).


🎯 Code Functionality

The script processes a WSI and its corresponding cell classification results through the following steps:

  1. Input Data Loading: Loads the WSI (.svs) using openslide and the cell classification data (coordinates, types) from a JSON file.
  2. Patch-wise Analysis: Iterates over the WSI in non-overlapping $1024 \times 1024$ pixel patches.
  3. Validation: Applies image-based checks (valid_patch function) to automatically skip patches that are mostly background, out-of-focus, or artifact-heavy.
  4. Patch Classification: For each valid patch, it counts neoplastic, connective, and inflammatory (lymphocyte) cells.
    • A patch is classified as Tumor if the neoplastic cell count exceeds a minimum threshold (TUMOR_COUNT_THRESHOLD) and is greater than the connective cell count.
    • A patch is classified as Stroma if the connective cell count exceeds a minimum threshold (STROMA_COUNT_THRESHOLD) and is greater than the neoplastic cell count.
  5. Lymphocyte Quantification: It calculates:
    • TIL: The total count of lymphocytes found within all patches classified as Tumor.
    • SIL: The total count of lymphocytes found within all patches classified as Stroma.
  6. Visualization: Generates a composite image for easy interpretation. This image displays:
    • The original WSI thumbnail.
    • The WSI thumbnail overlaid with visualization, where Tumor patches are highlighted with red rectangles and Stroma patches with blue rectangles.
    • Titles on the composite image summarize the final TIL and SIL counts.

πŸ“₯ Input Requirements

The script is configured to use the following file paths:

Variable Description Example Path/Value
wsi_path Path to the Whole Slide Image file. /path/to/.../wsi.svs
json_path Path to the JSON file containing cell segmentation and type data. /path/to/.../cells.json
font_path Path to a TrueType font file for image annotations. ARIAL.TTF
Label A simple string label for the WSI (used in the output title). 'CCC'

πŸ“€ Output

The main deliverable is a high-level summary visualization:

  • File: wsi_summary_visualization.png
  • Location: Saved to the directory specified by output_dir.
  • Content: A merged image showing the WSI visualization with colored patch boundaries and a title containing the final TIL and SIL metrics.

The script also prints the final TIL and SIL counts to the console.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published