MedVision / doc /dataset_skm-tea.md
YongchengYAO
update doc
bf953a1

Preparing SKM-TEA Data

MedVision is designed to download raw data from source and the annotations from our Huggingface dataset repo. For access to the raw data of the SKM-TEA dataset, you need to register at https://aimi.stanford.edu/datasets/skm-tea-knee-mri.

This tutorial is about:

  • What data to download from the source in order to use the annotations from MedVision?
  • How to preprocess the raw data?
  • How to structure the preprocessed files?

What data to download?

  • Download images from dicoms
  • Download masks from segmentation_masks/raw-data-track to Masks
# Files from SKM-TEA source
β”œβ”€β”€ v1-release
    β”œβ”€β”€ dicoms
        β”œβ”€β”€ MTR_001.tar.gz
        β”œβ”€β”€ ...
    β”œβ”€β”€ segmentation_masks
        β”œβ”€β”€ raw-data-track
            β”œβ”€β”€ MTR_001.nii.gz
            β”œβ”€β”€ ...
# local file structure
β”œβ”€β”€ [your folder]
    β”œβ”€β”€ Masks
        β”œβ”€β”€ MTR_001.nii.gz
        β”œβ”€β”€ ...
    β”œβ”€β”€ dicoms
        β”œβ”€β”€ MTR_001.tar.gz
        β”œβ”€β”€ ...

How to preprocess data?

⚠️ DO NOT change file or folder names. See why here.

  1. Go to the parent folder of dicoms, install dcm2niix, add processing script

    # local file structure
    β”œβ”€β”€ [your folder]
        β”œβ”€β”€ Masks
        β”œβ”€β”€ dicoms
        β”œβ”€β”€ prepare-skm-tea.sh # <-- add this
    
    # prepare-skm-tea.sh
    
    # Step 1: extract files
    mkdir -p dicoms-ext
    for f in dicoms/*.tar.gz; do
        tar -xvzf "$f" -C dicoms-ext
    done
    
    # Step 2: convert dcm to nii.gz
    mkdir -p niigz
    for d in dicoms-ext/MTR_*; do
        dcm2niix -z y -f %f -o niigz/ $d
    done
    
    # Step 3: move files
    mkdir -p Images-E1 Images-E2
    for f in niigz/*_e1.nii.gz; do
        base=$(basename "$f")             # remove path prefix
        mv "$f" "Images-E1/${base/_e1/}"  # rename and move
    done
    for f in niigz/*_e2.nii.gz; do
        base=$(basename "$f")
        mv "$f" "Images-E2/${base/_e2/}"
    done
    
    # clean up
    rm -r niigz
    rm -r dicoms-ext
    

    Expected file structure after running bash prepare-skm-tea.sh

    # local file structure
    β”œβ”€β”€ [your folder]
        β”œβ”€β”€ Masks
        β”œβ”€β”€ dicoms
        β”œβ”€β”€ Images-E1
        β”œβ”€β”€ Images-E2
        β”œβ”€β”€ prepare-skm-tea.sh
    
  2. Put these folders into SKM-TEA-nii and upload the compressed file to your HF dataset repo

    # DO NOT use other folder names
    β”œβ”€β”€ SKM-TEA-nii
        β”œβ”€β”€ Images-E1
        β”œβ”€β”€ Images-E2
        β”œβ”€β”€ Masks
    

    Your HF repo should contain SKM-TEA-nii.zip

  3. Set env var whenever you load SKM-TEA data from MedVision

    import os
    os.environ["MedVision_SKMTEA_HF_ID"] = <your-hf-dataset-id>