Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize manual correction scripts #2

Merged
merged 41 commits into from
Feb 1, 2023

Conversation

valosekj
Copy link
Member

@valosekj valosekj commented Jan 19, 2023

Description

This PR proposes an initial version of scripts for manual correction workflow. For details, see README.
The scripts are based on ukbiobank-spinalcord-csa scripts. To allow easy tracking of changes proposed in this PR, I pushed the ukbiobank-spinalcord-csa scripts to the main branch.

Compared ukbiobank-spinalcord-csa scripts, I added:

  • new input flags (-path-derivatives, -path-derivatives, -suffix-files-seg, -suffix-files-gmseg, -suffix-files-label, -label-list, -viewer) in f89a9ac
  • correction of gmseg in 291be5f
  • selection of viewer (FSLeyes, ITK-SNAP. 3D Slicer is not implemented yet, though) in 44a54f6
  • fetch_subject_and_session function (to unify get_subject and get_session under a single function) in 0e312aa and daf74dc
  • fetch_yaml_config function to simplify loading of yaml config file among scripts in 272c4c9
  • further improvements (such as manipulation with paths, comments to clarify code, etc.)

I would extremely appreciate feedback from SCT users, such as @sandrinebedard, @kiristern, @naga-karthik, @rohanbanerjee, and @mchen1110. You can test the PR using the instructions below or on some dataset you are currently working on.

This PR partly addresses #1. But still, a lot of features describes in spinalcordtoolbox/spinalcordtoolbox#3353 (comment) have to be implemented.

How to test this PR

  1. Clone repo, create venv, and install dependencies:
git clone https://github.com/spinalcordtoolbox/manual-correction.git
cd manual-correction
git checkout jv/generalize_manual_correction_scripts
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  1. Download the testing dataset. The dataset contains a sample output as provided by sct_run_batch. The dataset also includes the files_to_correct.yml file with a list of files for manual correction (obtained from the SCT QC html report.

  2. Run package_for_correction.py:

This simulates the real-world workflow in which a dataset is processed on a remote server, and you do not want to copy the whole dataset (GB of data). Instead, only the images and labels that need to be corrected (listed in files_to_correct.yml) are zipped by the package_for_correction.py:

python package_for_correction.py -path-in ~/manual_correction_example_dataset/data_processed -config ~/manual_correction_example_dataset/files_to_correct.yml -o ~/manual_correction_example_dataset/data_to_correct

(Now, you would have copied the zipped file from a server to your local machine. Since we are just simulating real-world workflow, the copy from a server to a local machine is skipped for now.)

  1. Run manual_correction.py:

The package_for_correction.py outputs data_to_correct.zip. Unzip this archive and run manual_correction.py:

python manual_correction.py -path-in ~/manual_correction_example_dataset/data_to_correct -config ~/manual_correction_example_dataset/files_to_correct.yml -path-out ~/Desktop/manual_correction_example_dataset -viewer fsleyes

Note: you can specify a viewer (FSLeyes, ITK-SNAP) for SC and GM segmentation corrections. (3D Slicer is not implemented yet)

First, you will have to enter your name (which will be used for .json sidecars). Then, the package_for_correction.py will iterate across files listed in files_to_correct.yml. It will gradually open FSLeyes (or ITK-snap) for SC and GM segmentation correction and sct_label_utils for disc label correction. The script saves manually corrected files under the derivatives/labels folder (you can change this folder by the -path-derivatives flag). The script also outputs a QC report (--> you can check how you corrected the labels).

Once finished, you can rerun the command. In this case, the script detects manually corrected files under derivatives/labels and asks you if you want to overwrite them.

Fixes: #1

…ng 'label_list' specifying labels to correct.
…ffix-files-label' to build the 'suffix_dict'.
The script allows copying of manually corrected labels (segmentations, vertebral labeling, etc.) from the preprocessed dataset to the git-annex BIDS dataset's derivatives folder
@valosekj valosekj marked this pull request as draft January 19, 2023 20:48
@rohanbanerjee rohanbanerjee self-requested a review January 20, 2023 00:16
@valosekj valosekj self-assigned this Jan 20, 2023
@naga-karthik naga-karthik self-requested a review January 24, 2023 17:50
@valosekj
Copy link
Member Author

@naga-karthik Thank you for the implementation of this super useful feature! 👍🏻

package_for_correction.py Outdated Show resolved Hide resolved
package_for_correction.py Outdated Show resolved Hide resolved
manual_correction.py Outdated Show resolved Hide resolved
manual_correction.py Outdated Show resolved Hide resolved
@valosekj valosekj marked this pull request as ready for review January 31, 2023 18:26
@valosekj
Copy link
Member Author

The PR is ready for merge. If there are no additional comments or suggestions, I will do merge.

@valosekj valosekj merged commit e8ecccf into main Feb 1, 2023
@mguaypaq mguaypaq deleted the jv/generalize_manual_correction_scripts branch February 6, 2023 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Summary of manual_correction.py and package_for_correction.py versions
3 participants