CXR Sextants β€” Zone-Based Detection of Pulmonary Lesions in Chest Radiographs

CXR Sextants is a decision-support module that performs binary (yes/no) classification of three types of pulmonary lesions β€” cavities, infiltrates (increased parenchymal density), and nodules β€” in each of the six anatomical zones ("sextants") of the lungs.

It is a component of a larger Flask-based AI-services web platform and is exposed through a standardized REST API.

⚠️ Research use only. This system is not intended to replace a radiologist and is not approved for clinical diagnosis. It is a decision-support tool that draws attention to suspicious areas and provides structured preliminary information.


Model Description

Chest radiography remains one of the most widely used diagnostic procedures, particularly in regions with a high prevalence of tuberculosis. Its interpretation, however, requires considerable experience and is known to be affected by observer fatigue and inter-reader variability. CXR Sextants provides automated preliminary analysis to support that workflow.

The lung fields are divided into six anatomical zones (three per lung: upper, middle, lower), a scheme traditional for radiological reporting of tuberculosis and other diffuse lung diseases. For each combination of zone and lesion type, the system produces a probability estimate, which can be used both for case prioritization and for generating a structured preliminary report.

Classifiers

Three separate Keras models are used, one per finding type:

Model Finding Radiological definition
cavs Cavities Air-containing spaces with a definable wall within the lung parenchyma. Characteristic of tuberculosis and some fungal infections, as well as abscesses and cavitating neoplasms.
dens Infiltrates Areas of increased parenchymal density, corresponding to increased attenuation due to consolidation or infiltration. Observed in pneumonia, tuberculosis with an exudative component, and other inflammatory processes.
nods Nodules Rounded focal opacities not exceeding 3 cm in diameter. May represent early malignancy, granulomas, or metastatic lesions.

Each model outputs a probability in [0, 1]. A threshold of 0.5 converts it to a binary label (below β†’ negative, above β†’ positive). Both the probability and the binary label are stored in the output JSON.

Zone codes

Right lung Left lung
R1 β€” upper L1 β€” upper
R2 β€” middle L2 β€” middle
R3 β€” lower L3 β€” lower

Nominal anatomical levels: the upper zone is superior to the anterior second rib, the middle zone lies between the second and fourth ribs, and the lower zone is inferior to the fourth rib.


Intended Use

Intended: research; retrospective analysis; case prioritization and triage support; generation of structured preliminary reports; a baseline for further methodological work on zone-based CXR classification.

Out of scope: primary or autonomous clinical diagnosis; use on pediatric radiographs (unless separately validated); use on modalities other than posteroanterior/anteroposterior chest radiographs; any use where a failure to detect a lesion could directly harm a patient without radiologist oversight.


Inputs and Preprocessing

The system accepts chest radiographs in DICOM or NIfTI format (.nii / .nii.gz), the standard container in medical image processing pipelines.

A pre-computed binary lung mask in NIfTI format with the same spatial dimensions is required. It is produced by a separate segmentation component of the platform and is stored alongside the input with the suffix -cxr_lungs.nii.gz. The mask is used to define the bounding box for zone cutting, to restrict analysis to lung tissue, and to build the visual overlay.

Preprocessing steps:

  1. Verify the file opens and contains a 2-D image (a dummy third dimension of size 1 is removed).
  2. Normalize pixel values to a standard range suitable for network input.
  3. For display: flip along one axis and transpose to the standard viewing orientation (patient's right on the image left, superior at the top), resample to isotropic spacing using the affine, and scale to fit a 512Γ—512 canvas with equal margins. The same geometric transformations are applied to the mask so that image and mask stay aligned.
  4. Per zone: resize the patch to a fixed square size, clip and rescale pixel values, and expand the array to the expected input shape (batch and channel dimensions).

Zone division

Zone boundaries are not derived from explicit rib detection. Instead, the SextantCutter component computes the bounding box of the combined lung mask (with a 3% margin) and finds two cut positions along the appropriate axis that divide the masked area into three parts of equal pixel count. This is more robust than anatomical landmark detection and yields reasonable boundaries even when lung position or shape is unusual. The right and left lungs are separated at the column midpoint of the bounding box, corresponding to the mediastinum.

Single-lung cases (e.g., after pneumonectomy, or a severely tilted image) are detected automatically from the distribution of the lung mask across the left and right halves. In such cases the visible lung is divided into three zones and predictions are emitted for the three applicable codes (R1/R2/R3 or L1/L2/L3).

Note on coordinates. Zone cutting operates in the coordinate system of the original NIfTI file, where the axes may not correspond to those of the display image: the flip and transpose applied for preview generation turn the left–right NIfTI axis into the row axis of the display image, and vice versa. Boundaries computed in NIfTI space must therefore be remapped to display space when drawing the overlay.


Outputs

JSON

A fixed structure with predictions for all six zones (R1, R2, R3, L1, L2, L3), each containing three sub-dictionaries for the three model types, plus fields for the detected lung side and the processing status (so that downstream components can handle edge cases such as single-lung images).

{
  "R1": {
    "cavs": {"probability": 0.07, "class": 0},
    "dens": {"probability": 0.81, "class": 1},
    "nods": {"probability": 0.22, "class": 0}
  },
  "R2": { "...": "..." },
  "lung_side": "both",
  "status": "ok"
}

Visual overlay

A semi-transparent colored layer is painted over each zone according to its severity score, defined as the maximum probability across the three classifiers. Maximum (rather than sum or average) is used because a zone is clinically of interest if any of the three lesion types shows an elevated probability; this avoids artificially inflating scores in zones with multiple moderate findings while preserving sensitivity to any single strong signal.

The color mapping follows a spectral ramp from blue (severity near 0) through cyan, green, yellow, and orange to red (severity near 1), blended at 45% opacity so the underlying anatomy stays visible. Each zone carries a small text label with the zone code and severity percentage, rendered with a dark outline for readability against light and dark backgrounds.

Text report

A structured text report lists each zone with a positive classifier result, provides the full radiological definition of the detected finding, and appends a brief glossary of zone boundaries. Reports are available in English and Russian. Report generation is implemented as a separate module that reads the output JSON and applies formatting templates, so the format or language set can be changed without touching the classification logic.


Usage

import keras

cavs = keras.saving.load_model("models/cavs.keras")   # cavities
dens = keras.saving.load_model("models/dens.keras")   # infiltrates
nods = keras.saving.load_model("models/nods.keras")   # nodules

# zone_patch: preprocessed sextant patch, shape (1, H, W, C)
p_cav = float(cavs.predict(zone_patch)[0][0])
label = int(p_cav > 0.5)

Downloading the weights directly from the Hub:

from huggingface_hub import hf_hub_download

path = hf_hub_download(repo_id="lab225/cxr-sextants", filename="models/cavs.keras")

For the full pipeline (NIfTI ingestion β†’ segmentation β†’ zone cutting β†’ classification β†’ JSON β†’ overlay β†’ report), see the accompanying code repository and Space linked below.


Training Data

TODO


Evaluation

Status: evaluation of the three released Keras classifiers is not yet complete. The figures below come from YOLOv8-based experiments conducted within the same research programme. Unless the released weights are exports of these same experiments, they must not be read as the performance of the cavs / dens / nods models in this repository.

Reference results (YOLOv8 experiments, cavities)

Setting Architecture Task granularity AUC Accuracy
Cavities, whole lungs YOLOv8 Whole-image (both lungs) 0.95 88%
Cavities, lung sextants YOLOv8 Per-zone (sextant) 0.89 76.9%

The drop from whole-image to per-zone operation (AUC 0.95 β†’ 0.89) is expected: each zone classifier sees only one sixth of the lung field, has far less anatomical context, and lesions lying near a zone boundary may be truncated across two patches.

Negative-class provenance. In the sextant experiment, approximately 40% of the healthy (negative) sextants were drawn from external datasets rather than from the same cohort as the positive examples. This is a material caveat: when negatives and positives originate from different acquisition sources, a classifier can achieve high apparent discrimination by learning source-specific characteristics β€” detector type, exposure, post-processing, digitization artifacts β€” instead of the pathology itself. The reported AUC should therefore be regarded as an upper bound until validated on negatives drawn from the same distribution as the positives.

Released models: per-zone evaluation

Pending.

Lesion Zones Accuracy Sensitivity Specificity ROC-AUC n (test) Positive rate
Cavities (cavs) all TODO TODO TODO TODO TODO TODO
Infiltrates (dens) all TODO TODO TODO TODO TODO TODO
Nodules (nods) all TODO TODO TODO TODO TODO TODO

Operating threshold: 0.5 (uniform across zones and lesion types; per-zone calibration is identified as future work).


Limitations and Known Failure Modes

  • Threshold is uncalibrated. A single 0.5 threshold is applied to every zone and every lesion type. Per-zone calibration is planned.
  • Zone boundaries are geometric, not anatomical. Equal-area division approximates the clinical upper/middle/lower scheme but does not detect ribs. Boundaries may deviate from the anatomical levels in atypical anatomy, marked rotation, or severe volume loss.
  • Segmentation dependency. The module requires an externally produced lung mask. Errors in segmentation propagate directly to zone placement and to the region seen by the classifiers. Fallback behavior exists for missing or incomplete masks, but degraded output should be expected.
  • Binary output only. The system reports presence/absence per zone, not lesion count, size, or precise localization within the zone.
  • Distribution shift. Performance on equipment, populations, or acquisition protocols differing from the training data has not been characterized.
  • Negative-class provenance / possible shortcut learning. In the reported sextant experiment, ~40% of healthy zones came from external datasets. Reported discrimination may partly reflect source recognition rather than lesion detection. Not yet quantified.
  • No pediatric validation.
  • Three lesion types only. Pleural, cardiovascular, mediastinal, and skeletal findings are not detected; a negative result does not imply a normal radiograph.

Ethical Considerations

The system is a decision-support tool operating in a high-stakes clinical domain. False negatives may delay diagnosis of tuberculosis or malignancy; false positives may trigger unnecessary follow-up imaging and radiation exposure. Outputs must always be reviewed by a qualified radiologist. Model performance may vary across demographic subgroups; subgroup analysis has not yet been performed. No patient-identifiable data is contained in this repository.


API and Deployment

The module is registered as a worker class within the AI-services platform, inheriting from a common base and implementing a standardized processing interface, so that applications can be added or processing backends replaced without changing infrastructure code.

Pipeline stages for a single case: file upload and registration β†’ data preparation (conversion to internal format) β†’ lung field segmentation via a pre-trained mask model β†’ zone-based classification with the three classifiers β†’ structured JSON output β†’ creation of preview images for the web interface. Stages are orchestrated by a worker manager maintaining a task queue; each stage is a separate method, so a failed stage can be restarted without repeating the whole pipeline. Status and error messages are written to a per-case log retrievable through the API.

The REST API covers the full lifecycle of a case: uploading files (directly or by URL), starting the analysis, checking processing status, retrieving results and preview images, and removing cases. Authentication is handled externally through the Ory Kratos identity management system; the application itself does not manage user credentials.


Future Work

  • Calibration of model thresholds per zone.
  • Integration of explicit anatomical landmark detection for more precise zone boundaries.
  • Extension of the classifier set to additional pathology types.

License

The code and the model weights in this repository are released under the Apache License, Version 2.0. A copy of the license is available in the LICENSE file and at https://www.apache.org/licenses/LICENSE-2.0.

Copyright 2026 NIH/NIAID, UIIP NASB

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Use of the underlying data

Apache-2.0 governs this software and these weights only. It does not grant any rights to the clinical data used for training, which remains subject to its own data use agreement. Users who publish work derived from this model are asked to acknowledge the data source in accordance with the applicable citation guidelines.

Disclaimer

Nothing in this license authorizes clinical use. This model is provided for research purposes only, is not a certified medical device, and must not be used for primary or autonomous diagnosis.


Citation

Acknowledgements

Developed under ISTC Project No. PR150.

Contact

kosarevaaleksandra4317@gmail.com, eduard.snezhko@gmail.com

Downloads last month
185
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using lab225/cxr-sextants 1