Skip to content

Codebase for the paper Leveraging the Mahalanobis Distance to enhance Unsupervised Brain MRI Anomaly Detection

Notifications You must be signed in to change notification settings

FinnBehrendt/Mahalanobis-Unsupervised-Anomaly-Detection

Repository files navigation

Mahalanobis Distance for Anomaly Detection in Brain MRI

Codebase for our MICCAI 24 paper Leveraging the Mahalanobis Distance to enhance Unsupervised Brain MRI Anomaly Detection.

Abstract: Unsupervised Anomaly Detection (UAD) methods rely on healthy data distributions to identify anomalies as outliers. In brain MRI, a common approach is reconstruction-based UAD, where generative models reconstruct healthy brain MRIs, and anomalies are detected as deviations between input and reconstruction. However, this method is sensitive to imperfect reconstructions, leading to false positives that impede the segmentation. To address this limitation, we construct multiple reconstructions with probabilistic diffusion models. We then analyze the resulting distribution of these reconstructions using the Mahalanobis distance to identify anomalies as outliers. By leveraging information about normal variations and covariance of individual pixels within this distribution, we effectively refine anomaly scoring, leading to improved segmentation. Our experimental results demonstrate substantial performance improvements across various data sets. Specifically, compared to relying solely on single reconstructions, our approach achieves relative improvements of 15.9%, 35.4%, 48.0%, and 4.7% in terms of AUPRC for the BRATS21, ATLAS, MSLUB and WMH data sets, respectively.

Data

We use the IXI data set, the BraTS21, MSLUB, ATLAS_v2 and WMH data set for our experiments. You can download/request the original data sets here:

If you’d like to use our preprocessed data, we’ve made preprocessed versions of the datasets available here (approx. 37G).

After downloading, the directory structure of <DATA_DIR> should look like this:

<DATA_DIR>
├── Train
│   ├── ixi
│   │   ├── mask
│   │   ├── t2
│    │  └── t1
├── Test
│   ├── Brats21
│   │   ├── mask
│   │   ├── t2
│   │   └──seg
│   ├── MSLUB
│   │   ├── mask
│   │   ├── t2
│   │   └── seg
│   ├── ATLAS_v2
│   │   ├── mask
│   │   ├── t1
│   │   └── seg
│   └── ...
├── splits
│   ├──  Brats21_test.csv        
│   ├──  Brats21_val.csv   
│   ├──  MSLUB_val.csv 
│   ├──  MSLUB_test.csv
│   ├──  IXI_train_fold0.csv
│   ├──  IXI_train_fold1.csv 
│   └── ...                
└── ...

You should then specify the location of <DATA_DIR> in the pc_environment.env file. Additionally, specify the <LOG_DIR>, where runs will be saved.

Environment Set-up

To download the code type

git clone git@github.com:FinnBehrendt/Mahalanobis-Unsupervised-Anomaly-Detection.git

In your linux terminal and switch directories via

cd Mahalanobis-Unsupervised-Anomaly-Detection

To setup the environment with all required packages and libraries, you need to install anaconda first.

Then, run

conda env create -f environment.yml -n mhd-uad

and subsequently run

conda activate mhd-uad
pip install -r requirements.txt

to install all required packages.

Run Experiments

To run the training of the cDDPM, run

python run.py experiment=cDDPM/DDPM_cond_spark_2D model.cfg.pretrained_encoder=False

For slightly better performance, you can pretrain the encoder via masked pretraining (Spark)

python run.py experiment=cDDPM/Spark_2D_pretrain

Having pretrained the encoder, you can now run

python run.py experiment=cDDPM/DDPM_cond_spark_2D encoder_path=<path_to_pretrained_encoder>

The <path_to_pretrained_encoder> will be placed in the <LOG_DIR>. Alternatively, you will find the best checkpoint path printed in the terminal. For more details of the cDDPM and training, see the original cDDPM repo and paper.

Having trained the cDDPM, you can run the MHD evaluation with

python run.py experiment=MHD/cDDPM_MHD load_checkpoint=<path_to_trained_cDDPM> datamodule.cfg.mode=t2 

for T2 and

python run.py experiment=MHD/cDDPM_MHD load_checkpoint=<path_to_trained_cDDPM> datamodule.cfg.mode=t1 

for T1 weighted scans.

Citation

If you make use of our work, we would be happy if you cite it via

@inproceedings{10.1007/978-3-031-72120-5_37,
	abstract = {Unsupervised Anomaly Detection (UAD) methods rely on healthy data distributions to identify anomalies as outliers. In brain MRI, a common approach is reconstruction-based UAD, where generative models reconstruct healthy brain MRIs, and anomalies are detected as deviations between input and reconstruction. However, this method is sensitive to imperfect reconstructions, leading to false positives that impede the segmentation. To address this limitation, we construct multiple reconstructions with probabilistic diffusion models. We then analyze the resulting distribution of these reconstructions using the Mahalanobis distance to identify anomalies as outliers. By leveraging information about normal variations and covariance of individual pixels within this distribution, we effectively refine anomaly scoring, leading to improved segmentation. Our experimental results demonstrate substantial performance improvements across various data sets. Specifically, compared to relying solely on single reconstructions, our approach achieves relative improvements of 15.9{\%}, 35.4{\%}, 48.0{\%}, and 4.7{\%} in terms of AUPRC for the BRATS21, ATLAS, MSLUB and WMH data sets, respectively.},
	address = {Cham},
	author = {Behrendt, Finn and Bhattacharya, Debayan and Mieling, Robin and Maack, Lennart and Kr{\"u}ger, Julia and Opfer, Roland and Schlaefer, Alexander},
	booktitle = {Medical Image Computing and Computer Assisted Intervention -- MICCAI 2024},
	editor = {Linguraru, Marius George and Dou, Qi and Feragen, Aasa and Giannarou, Stamatia and Glocker, Ben and Lekadir, Karim and Schnabel, Julia A.},
	isbn = {978-3-031-72120-5},
	pages = {394--404},
	publisher = {Springer Nature Switzerland},
	title = {Leveraging the Mahalanobis Distance to Enhance Unsupervised Brain MRI Anomaly Detection},
	year = {2024}}

About

Codebase for the paper Leveraging the Mahalanobis Distance to enhance Unsupervised Brain MRI Anomaly Detection

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages