Cookbook 61: Offline Oncology Mammography Microcalcification & Tumor Classifier

This cookbook details how to deploy a localized oncology mammography analysis engine to detect pleomorphic microcalcifications, focal masses, and architectural distortions directly from full-field digital mammograms (FFDM) in DICOM format without external cloud API dependencies.

1. Overview & Use Case

Mammographic screening requires high-precision detection of subtle microcalcification clusters and non-palpable soft tissue masses. In decentralized breast screening units and rural oncology centers, instant CAD (Computer-Aided Detection) assistance improves diagnostic sensitivity and reduces false-negative recall rates.

This engine enables:

       [ Digital Mammogram / DICOM (CC & MLO Views) ]
                              │
                              ▼
                   [ MammoNet-BI-RADS-v1 ] 
                   ├── Microcalcification Heatmap
                   └── Mass Boundary Segmentation
                              │
                              ▼
                  [ BI-RADS-Scoring-CLI ]
                  ├── Spiculation Micrometry
                  └── BI-RADS Category (1-5)
                              │
                              ▼
         [ Structured Oncology Diagnostic Summary JSON ]

2. Installation & Prerequisites

Ensure Python 3.10+, pydicom, torch, torchvision, and OpenCV are installed:

pip install pydicom torch torchvision opencv-python-headless numpy

Clone the offline model weights:

git clone https://github.com/OpenPHRorg/mammo-net-local.git
cd mammo-net-local

3. Mammogram DICOM Preprocessing

Breast tissue density calibration and contrast normalization (CLAHE) to expose microcalcification structures:

import pydicom
import cv2
import numpy as np

def preprocess_mammogram(dicom_path):
    ds = pydicom.dcmread(dicom_path)
    pixel_array = ds.pixel_array.astype(float)
    
    # Invert photometric interpretation if MONOCHROME1
    if getattr(ds, 'PhotometricInterpretation', '') == 'MONOCHROME1':
        pixel_array = np.max(pixel_array) - pixel_array

    # Normalize to standard 8-bit range
    norm_img = ((pixel_array - np.min(pixel_array)) / (np.max(pixel_array) - np.min(pixel_array)) * 255).astype(np.uint8)
    
    # Apply Contrast Limited Adaptive Histogram Equalization (CLAHE)
    clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8))
    enhanced_img = clahe.apply(norm_img)
    
    return enhanced_img

# Example usage
prep_img = preprocess_mammogram("sample_mammo_cc.dcm")
cv2.imwrite("preprocessed_mammo.png", prep_img)
print("Mammogram preprocessing completed.")

4. Inference & BI-RADS Scoring

Execute localized tumor segmentation and microcalcification risk grading:

import torch

def evaluate_mammogram(enhanced_image):
    # Simulated model output tensor [batch, channels, H, W]
    # Classifies: 0: Normal, 1: Benign Calcification, 2: Suspicious Microcalcifications, 3: Spiculated Mass
    model = torch.hub.load('OpenPHRorg/mammo-net-local', 'mammo_birads_v1', pretrained=True)
    model.eval()

    tensor_input = torch.from_numpy(enhanced_image).unsqueeze(0).unsqueeze(0).float() / 255.0
    
    with torch.no_grad():
        logits, birads_scores = model(tensor_input)
        predicted_class = torch.argmax(logits, dim=1).item()
        birads_category = torch.argmax(birads_scores, dim=1).item() + 1
        
    return {
        "finding_type": ["Normal", "Benign Calcifications", "Pleomorphic Microcalcifications", "Spiculated Mass"][predicted_class],
        "birads_category": f"BI-RADS {birads_category}",
        "confidence": float(torch.softmax(logits, dim=1)[0][predicted_class].item())
    }

# Run assessment
result = evaluate_mammogram(prep_img)
print(f"Diagnostic Result: {result}")

5. Verification & Summary

This engine delivers instant, offline oncology screening reports conforming to ACR BI-RADS reporting standards.