2DMamba: Efficient State Space Model for Image Representation with Applications on Giga-Pixel Whole Slide Image Classification

Jingwei Zhang, Anh Tien Nguyen, Xi Han, Vincent Quoc-Huy Trinh, Hong Qin, Dimitris Samaras, Mahdi S. Hosseini

This paper, presented at CVPR 2024, introduces 2DMamba, a significant evolution of the Mamba architecture designed specifically for two-dimensional data like medical slides and natural images. By introducing a hardware-optimized 2D scan operator, it achieves state-of-the-art performance in gigapixel Whole Slide Image (WSI) classification while maintaining high computational efficiency.

The Challenge of Spatial Context in Gigapixel Imaging

In fields like computational pathology, researchers work with Whole Slide Images (WSIs)—massive files that can reach 100,000 x 100,000 pixels. Processing these is a significant challenge for traditional models:

  1. Transformers suffer from quadratic complexity, meaning memory and compute requirements explode as image size grows.
  2. 1D Mamba (SSM) models offer linear complexity but require flattening 2D images into 1D sequences. This creates "spatial discrepancy": pixels that are vertically adjacent in an image end up far apart in a 1D string, causing the model to lose critical spatial relationships.
  3. Conventional Multiple Instance Learning (MIL) often treats image patches as an unordered bag, losing spatial context entirely.
Comparison of spatial context handling in Conventional MIL, 1D Mamba, and the proposed 2DMamba.

2DMamba bridges this gap by creating a truly 2D-aware Mamba that preserves spatial continuity without the overhead of Transformers.

The 2DMamba Architecture

The authors propose three key innovations to enable efficient 2D processing:

2D Selective Scan

Instead of flattening the image, 2DMamba performs horizontal and vertical scans in parallel. This ensures that the "distance" between pixels in the model's memory corresponds to their actual Manhattan distance on the 2D grid, preserving spatial continuity. In SSMs, the model's ability to remember a pixel's influence decays over distance; by using a 2D scan, the maximum distance between any two points is drastically reduced compared to a 1D scan.

Hardware-Aware Operator

The team developed a custom CUDA kernel called SegmentedBlockScan. Standard GPU libraries are optimized for 1D sequences and require heavy padding for 2D grids, which can waste over 50% of computation. SegmentedBlockScan allows for simultaneous multi-row/column scanning with minimal overhead, matching the speed of highly optimized 1D Mamba implementations.

2DMambaMIL Framework

For medical imaging, they introduce a learnable non-tissue token to represent empty space around a biopsy. This allows the model to maintain a perfect 2D grid even when the tissue sample is irregularly shaped.

The 2DMamba block architecture and the 2D selective scan algorithm.

Experimental Results

The model was rigorously tested across multiple domains, including WSI classification, survival analysis, and natural image tasks (ImageNet-1K and ADE20k).

  • Medical Imaging: 2DMamba improved WSI classification by up to 2.48% in AUC and 3.11% in F1 score over previous state-of-the-art methods. In survival analysis, it achieved a 5.52% boost in C-index.
  • Natural Images: When integrated into the VMamba architecture, it improved semantic segmentation (mIoU) on the ADE20k dataset by 0.5 to 0.7 points.
  • Qualitative Success: Attention heatmaps demonstrate that 2DMamba focuses more accurately on actual tumor regions compared to 1D Mamba models, which are often distracted by non-critical background tissue.

Conclusion

2DMamba demonstrates that the specific way an image is scanned matters. While other models attempt multi-way 1D scans, 2DMamba’s intrinsic 2D recursion is mathematically superior for capturing cell-to-cell interactions in pathology. While throughput may slightly decline for extremely large feature maps due to dual-axis scanning, its efficiency and accuracy make it a powerful tool for high-resolution image analysis. Future work will explore multi-scale designs and applications in 3D video or volumetric medical scans.

Summary updated

BibTeX
@inproceedings{zhang2025dmamba,
  author = {Jingwei Zhang and Anh Tien Nguyen and Xi Han and Vincent Quoc-Huy Trinh and Hong Qin and Dimitris Samaras and Mahdi S. Hosseini},
  title = {{2DMamba: Efficient State Space Model for Image Representation with Applications on Giga-Pixel Whole Slide Image Classification}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2025},
  doi = {10.1109/cvpr52734.2025.00339},
}
Figure