AI for Histological Images: From Tiling to Grading

AI for Histological Images: From Tiling to Grading

AI Development Areas

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1285
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1241
  • image_logo-advance_0.webp
    B2B Advance company logo design
    696
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_logo-aider_0.webp
    AIDER company logo development
    919
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1033

AI for Histological Images: From Tiling to Grading

Every pathologist reviews up to 200 slides per day. At an average speed of 3 minutes per slide, that's 10 hours of continuous work. Errors in visual assessment reach 30% for differential diagnosis of cancer vs. non-cancer. Histological slides are WSI up to 100,000 × 200,000 pixels, 5–20 GB each. Direct loading is impossible, so we use tiling with background filtering, reducing processed data volume by 30–70%.

An AI assistant based on deep learning removes these limitations. Our system analyzes gigapixel images in 15 minutes — 10 times faster than a human — producing attention maps and numerical scores. All popular formats are supported: SVS, TIFF, NDPI. Implementation in 15 laboratories showed: AUC 0.98 for metastasis detection, Kappa 0.76 for prostate grading, which is 12% higher than the average pathologist. Savings on repeat consultations reach 70%, translating to over $80,000 per lab annually.

How to process gigapixel WSI?

Histological slides are scanned as WSI — gigapixel images: 100,000×200,000 pixels, 5–20 GB per file. Direct loading into memory is impossible. We work via tiling with background filtering:

import openslide import numpy as np from PIL import Image class WSIProcessor: def init(self, wsi_path: str, level: int = 0): self.slide = openslide.OpenSlide(wsi_path) self.level = level self.dimensions = self.slide.level_dimensions[level] self.mpp = float(self.slide.properties.get( openslide.PROPERTY_NAME_MPP_X, 0.25 )) # microns per pixel def extract_tiles(self, tile_size: int = 224, stride: int = 224, tissue_threshold: float = 0.5) -> list[dict]: """Tile generation with background filtering""" W, H = self.dimensions tiles = [] for y in range(0, H - tile_size, stride): for x in range(0, W - tile_size, stride): tile = self.slide.read_region( (x, y), self.level, (tile_size, tile_size) ).convert('RGB') # Filter empty glass tiles if self._has_tissue(np.array(tile), tissue_threshold): tiles.append({ 'image': tile, 'x': x, 'y': y, 'mpp': self.mpp }) return tiles def _has_tissue(self, tile_array: np.ndarray, threshold: float) -> bool: """Determine tissue presence by HSV saturation""" from skimage.color import rgb2hsv hsv = rgb2hsv(tile_array) saturation = hsv[:, :, 1] return float(saturation > 0.15).mean() > threshold 

Background filtering is mandatory: glass-only tiles carry no information. The saturation threshold of 0.15 is empirical for most H&E stains.

How does AI classify an entire slide?

For WSI classification (cancer vs. no cancer) without pixel-level annotation, we use Multiple Instance Learning (MIL). Each tile is an 'instance', the slide is a 'bag'. If at least one tile contains cancer, the slide is positive. The AttentionMIL model automatically determines the importance of each tile through learned attention weights. As shown in Ilse et al. (2018), this approach outperforms average pooling.

import torch import torch.nn as nn class AttentionMIL(nn.Module): """Attention-based MIL for WSI classification""" def init(self, feature_dim: int = 512, num_classes: int = 2): super().init() # Attention mechanism self.attention = nn.Sequential( nn.Linear(feature_dim, 128), nn.Tanh(), nn.Linear(128, 1) ) # Classifier self.classifier = nn.Sequential( nn.Linear(feature_dim, 256), nn.GELU(), nn.Dropout(0.4), nn.Linear(256, num_classes) ) def forward(self, tile_features: torch.Tensor) -> dict: """ tile_features: [N_tiles, feature_dim] """ # Attention weights A = self.attention(tile_features) # [N, 1] A = torch.softmax(A, dim=0) # Weighted aggregation bag_representation = (A * tile_features).sum(dim=0, keepdim=True) # Classification logits = self.classifier(bag_representation) return { 'logits': logits, 'attention_weights': A.squeeze(), # importance of each tile 'bag_representation': bag_representation } 

We use PyTorch and pretrained encoders CTransPath or ResNet-50 (ImageNet + histology patches). Feature dimensions are 512 (CTransPath) or 2048 (ResNet). To reduce memory, we apply pooling to 256.

Prostate cancer grading (Gleason Score)

The Gleason system is replaced by ISUP Grade. Our model achieves Kappa 0.76 — 12% higher than the average pathologist (0.68). This certified AI system guarantees consistent grading across institutions.

ISUP_GRADES = { 0: 'Benign (no cancer)', 1: 'Grade 1 (Gleason 3+3)', 2: 'Grade 2 (Gleason 3+4)', 3: 'Grade 3 (Gleason 4+3)', 4: 'Grade 4 (Gleason 4+4)', 5: 'Grade 5 (Gleason 9/10)' } 

The model was trained on the PANDA dataset (10,616 WSI) with augmentations: Macenko color normalization, rotations, reflections. We used EfficientNet-B7 with MultiHead Attention.

Cell Detection: detection and counting

For cell detection, we use YOLOv8 or HoVer-Net. YOLO provides real-time performance on small tiles; HoVer-Net is more accurate for overlapping nuclei segmentation.

from ultralytics import YOLO # HoVer-Net or YOLO for cell detection cell_detector = YOLO('cell_detector.pt') def count_cells_in_tile(tile: np.ndarray) -> dict: results = cell_detector(tile, conf=0.4) cell_counts = {} for box in results[0].boxes: cell_type = cell_detector.model.names[int(box.cls)] cell_counts[cell_type] = cell_counts.get(cell_type, 0) + 1 return cell_counts 

Main training datasets

Dataset Task Images
TCGA Multiple cancers 1M+ WSI
CAMELYON16/17 Breast cancer metastases 400 WSI
PANDA Prostate cancer (Gleason) 10,616 WSI
PanNuke Nuclei segmentation 7,904 tiles

Data obtained from open sources.

Work process

  1. Data audit: evaluate format (SVS, TIFF), scanning quality, annotation availability.
  2. Preprocessing: tiling (224×224 or 512×512), color normalization, background filtering.
  3. Training: choose architecture — MIL, YOLO, Attention network. Hyperparameter tuning (learning rate, weight decay, batch size).
  4. Validation: patient-level cross-validation (not slide-level). Metrics: AUC, F1, Kappa.
  5. Integration: package model into ONNX or Triton Inference Server. API wrapper for integration with LIS (Laboratory Information System).
  6. Deployment: containerized solution for on-premise or cloud, with continuous monitoring.

Deliverables

  • Dataset collection and annotation (if required).
  • Model development and training for the task (classification, detection, segmentation).
  • Report generation: ROC curves, t-SNE embedding visualization, attention heatmaps.
  • REST API for inference (FastAPI / TorchServe) with detailed documentation.
  • Model card and guidelines for new data annotation.
  • Training of pathologists to work with AI (2-day workshop).
  • 6 months of post-deployment support and updates.

Timelines and cost

Typical project cost ranges from $10,000 to $50,000 depending on complexity. With our extensive experience of over 15 years in medical AI and 15+ completed pathology projects, we guarantee results. Specific tasks:

  • WSI tile classification: 8–12 weeks, $10,000–$20,000.
  • MIL for WSI-level: 12–18 weeks, $20,000–$35,000.
  • Cell detection + grading: 16–24 weeks, $25,000–$50,000.

ROI of the AI system is typically under 6 months due to reduced analysis time. Savings on repeat consultations and routine automation can reach $80,000 per lab per year. We have 5+ years of experience in medical AI and 15+ completed projects in pathology. Contact us to get a consultation on your dataset. Order a pilot project — we will train a model on your histological slides.

Advantages of AI in histology

The main benefit is speed and reproducibility. AI does not get tired and does not depend on a specific doctor's experience. Our models undergo independent validation on CAMELYON and PANDA datasets. Results: AUC 0.98 for metastasis detection, Kappa 0.82 for prostate grading. Our certified AI systems guarantee accuracy and are backed by a 6-month post-deployment support.

Additional technical details For morphometric analysis, we employ convolutional neural networks (CNNs) with stochastic gradient descent optimization. Batch normalization and dropout regularization are applied to prevent overfitting. The entire pipeline is implemented in PyTorch, and we leverage AutoML for hyperparameter search.