Skip to main content

Package for calculating Fréchet Radiomics Distance (FRD)

Project description

Fréchet Radiomics Distance (FRD)

This repository contains code implementing the FRD, proposed in Towards Learning Contrast Kinetics with Multi-Condition Latent Diffusion Models.

FRD measures similarity of radiomics features between two datasets.

frd overview

The lower the FRD, the more similar the datasets are in terms of radiomics features.

FRD is applicable to both 3D (nii.gz) and 2D (png, jpg, tiff) radiological images.

It is calculated by computing the Fréchet distance between two Gaussians fitted to the extracted and normalized radiomics features.

In general, the variability (e.g. measured via FRD) of imaging biomarkers (e.g. radiomics features) between two datasets (e.g. a real and a synthetic dataset) can be interpreted as quality/utility metric (e.g. of a synthetic dataset).

Installation

Install frd:

pip install frd-score

Requirements:

  • python3
  • pyradiomics
  • SimpleITK
  • pillow
  • numpy
  • opencv_contrib_python_headless
  • scipy

Usage

Run via CLI:

To compute the FID score between two datasets, where images of each dataset are contained in an individual folder:

python -m frd_score path/to/dataset_A path/to/dataset_B

If you would like to use masks to localize radiomics features, you can provide the path to the masks as follows:

python -m frd_score path/to/dataset_A path/to/dataset_B -M path/to/mask_A path/to/mask_B

Run in your code:

If you would like to import frd as a module, you can use the following code snippet:

from frd_score import frd

paths=['path/to/dataset_A', 'path/to/dataset_B']

# optionally, use masks.
paths_masks=[path_mask_A, path_mask_B] 

frd_value = frd.compute_frd(paths, paths_masks=paths_masks) 

Instead of providing the path to a folder, you may also directly provide a list to image paths (and/or masks).

img_paths_A = ['path/to/image1', 'path/to/image2']
img_paths_B = ['path/to/image3', 'path/to/image4']

paths=[img_paths_A, img_paths_B]

frd_value = frd.compute_frd(paths) 

Additional arguments

--paths_masks or -M: The two paths to the masks of the two datasets. The masks should have the same dimensions as the images. The masks should be binary images, where the region of interest is white (pixel value 255) and the background is black (pixel value 0). Masks are used to localize radiomics features.

--feature_groups or -f: You may define a subset of radiomics features to calulate the FRD. Currently, a list of all features is used as default, i.e. firstorder, glcm, glrlm, gldm, glszm, ngtdm, shape, shape2D

--norm_range or -R: The allowed value range of features in format [min, max]. Based on these values the frd features will be normalized. For comparability with FID, the default is [0, 7.45670747756958] which is an observed range for features of the Inception classifier in FID.

--norm_type or -T: The strategy with which the frd features will be normalized. Can be minmax or zscore.

--norm_across or -A: If set, indicates that normalization will be computed on all features from both datasets (e.g. synthetic, real) instead of on the features of each dataset separately.

--resize_size or -r: You may indicate an integer here to resize the x and y pixel/voxel dimensions of the input images (and masks) using cv2.INTER_LINEAR interpolation. For example resize_size=512 will resize an image of dims of e.g. (224, 244, 120) to (512, 512, 120).

--save_features or -F: Indicates whether radiomics feature values (normalized and non-normalized) should be stored in a csv file in the parent dir of path/to/dataset_A. This can be useful for reproducibility and interpretability.

--verbose or -v: You may enable more detailed logging.info and logging.debug console logs, as well as radiomics.logging.warning logs, by providing the verbose argument.

--num_workers or -w: The number of cpu workers used for multiprocessing during feature extraction. If set to None, then the system's number of available cpu cores minus 2 will be taken as default (1 is the minimum value for num_workers).

--save-stats or -s: As in pytorch-fid, you can generate a compatible .npz archive of a dataset using the --save-stats flag. You may use the .npz archive as dataset path, which can be useful to compare multiple models against an original dataset without recalculating the statistics multiple times.

python -m frd_score --save-stats path/to/dataset path/to/npz_outputfile

Citing

If you use this repository in your research, consider citing it using the following Bibtex entry:

@article{osuala2024towards,
  title={{Towards Learning Contrast Kinetics with Multi-Condition Latent Diffusion Models}},
  author={Osuala, Richard and Lang, Daniel and Verma, Preeti and Joshi, Smriti and Tsirikoglou, Apostolia and Skorupko, Grzegorz and Kushibar, Kaisar and Garrucho, Lidia and Pinaya, Walter HL and Diaz, Oliver and others},
  journal={arXiv preprint arXiv:2403.13890},
  year={2024}

Acknowledgements

An initial implementation was provided by Preeti Verma.

This repository borrows code from the pytorch-fid repository, the official pytorch implementation of the Fréchet Inception Distance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

frd_score-0.0.2.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

frd_score-0.0.2-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file frd_score-0.0.2.tar.gz.

File metadata

  • Download URL: frd_score-0.0.2.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for frd_score-0.0.2.tar.gz
Algorithm Hash digest
SHA256 47017dddee321626b5a4eda257192f84660a7c69015ec9a8dfeb58ae3a417e76
MD5 f2a5121e58d225c23577840225e4e3d3
BLAKE2b-256 3ed2ad3d56cbf7a53e6595d14e32b7e8c47dd13f393aba4e3ddc18c9a65efd1a

See more details on using hashes here.

File details

Details for the file frd_score-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: frd_score-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for frd_score-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 521b1008888e5347d1e3289119ea0752c580669df1b6872dd6051952bd8b3cf1
MD5 54e4ac132c768da286cb947e6b910364
BLAKE2b-256 056d503edbb330aa2ec9188ea000c7fc2a532229e6ecfe7a782a396498c55410

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page