From 90d83788e46e5be80a12676096acb944f0e56086 Mon Sep 17 00:00:00 2001 From: Julien Cohen-Adad Date: Fri, 16 Jul 2021 12:45:50 -0400 Subject: [PATCH] Clarified documentation --- README.md | 39 +++++++++-------------- make_figures_compare_SNR.py | 63 ------------------------------------- 2 files changed, 14 insertions(+), 88 deletions(-) delete mode 100755 make_figures_compare_SNR.py diff --git a/README.md b/README.md index 128cfad..3b6a24b 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,20 @@ At the end of the processing, you can review: |9584 |17.143453301063012|21.092693041826486|1.1247654335215769| |9418 |19.558182966645223|19.61176661536486 |1.1093208813636863| +## Description of the analysis -## Description of the scripts +Two NIfTI files are required: an initial scan and a re-scan without repositioning. The analysis script `process_data.sh` +includes the following steps: + +- Check if a mask for the spinal cord and/or gray matter already exists. If not, segment them automatically. +- Register the second scan to the first one. Use nearest-neighbour interpolation to preserve noise properties. +- Compute white matter mask by subtracting the spinal cord and the gray matter masks. +- Compute `SNR_diff` using the two-image subtraction method (Dietrich et al. J Magn Reson Imaging, 2007). +- Compute `SNR_mult` using the first scan (Griffanti et al., Biomed Sign Proc and Control, 2012). +- Compute `Contrast` by dividing the mean signal in the GM by that in the WM, on a slice-by-slice basis and then + average across slices. + +## Simulations * [simu_create_phantom.py](./simu_create_phantom.py): Generate synthetic phantom of WM and GM that can be used to validate the proposed evaluation metrics. The phantoms are generated with random noise, @@ -55,30 +67,7 @@ This script is particularly useful for processing the large amount of files generated by the phantom construction. * [simu_make_figures.py](./simu_make_figures.py): Make figures to assess metrics sensitivity to image quality. Run after simu_process_data.py -* [make_figures_compare_SNR.py](./make_figures_compare_SNR.py): Make figures to assess -the correlation between SNR_single and SNR_diff. - -## Analysis - -Two NIfTI files are required: an initial scan and a re-scan without repositioning. - -### Pre-processing -- The second image is registered to the first in order to compute the SNR using the two-image subtraction method. -- The spinal cord and gray matter of each image are segmented automatically. -- White matter segmentation is generated by subtracting the gray matter segmentation from the cord segmentation. - -### Signal-to-noise ratio (SNR): -The SNR is determined with two different methods: SNR_diff and SNR_single. -- SNR_diff is computed with SCT using the two-image subtraction method (Dietrich et al. J Magn Reson Imaging, 2007). -- SNR_single is computed from a single image (Griffanti et al., Biomed Sign Proc and Control, 2012). - -### Contrast: -The mean signal is computed in the white matter and gray matter of image 1. The contrast is then computed according to the following equation: - -~~~ -Contrast = abs(mean(WM) - mean(GM)) / min{mean(WM),mean(GM)} -~~~ - + ## Configuration of Niftyweb server - make sure the script WMGM is declared in `PATH` - add an entry to the crontab that points to the Daemon. Example (to edit, use `crontab -e`): diff --git a/make_figures_compare_SNR.py b/make_figures_compare_SNR.py deleted file mode 100755 index 6ee31a0..0000000 --- a/make_figures_compare_SNR.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -# Make figures to compare SNR methods: SNR_diff versus SNR_single. -# This script will loop across all subjects, retrieve the results/results.csv and generate a plot. -# -# USAGE: -# The script should be launched using SCT's python: -# ${SCT_DIR}/python/bin/python simu_make_figures_compare_SNR.py -i PATH_TO_DATA -# -# OUTPUT: -# Fig -# -# Authors: Nicolas Pinon - -import os -import argparse -import pandas as pd -import matplotlib.pyplot as plt - - -def get_parameters(): - parser = argparse.ArgumentParser(description='Generate a figure which compares the two SNR methods : SNR_single VS' - 'SNR_diff . Run after simu_process_data.py') - parser.add_argument("-i", "--input", - help="List here the path to the data, which should include all the patients directory", - required=True) - args = parser.parse_args() - return args - - -def main(): - - os.chdir(data_path) # making the path provided by the user the cwd - SNR_diff,SNR_single = [],[] - - for folder in os.listdir('.'): # going trough all folders - try: - os.chdir(data_path + '/' + folder + '/' + 'results') - # in each subjects folder's there should be a folder named 'results' and inside a csv file named 'results.csv' - results = pd.read_csv('results.csv') - SNR_diff.append(results.iat[0,1]) - SNR_single.append(results.iat[2, 1]) - except: # if there is something else than a subject's folder or if there is no csv results in the folder - pass - - - _, ax = plt.subplots(figsize=(6, 6)) - ax.scatter(SNR_diff, SNR_single, c=".3", color='blue') - ax.plot(ax.get_xlim(), ax.get_ylim(), color='blue', ls="--", c=".3") # adding a y=x line to show correlation - plt.xlabel('SNR_diff', color='blue', fontsize=15) - plt.ylabel('SNR_single', color='blue', fontsize=15) - plt.title('Correlation between SNR_single and SNR_diff') - - os.chdir(data_path) - plt.savefig('SNR_diff_VS_SNR_single.png') - plt.show() - - - -if __name__ == "__main__": - args = get_parameters() - data_path = args.input - main()