neuropoly / paradim-segmentation-brain

Repository for implementing pre-existing brain segmentation models trained with deep learning in PARADIM
MIT License
2 stars 0 forks source link

Script dicom to dicom using Freesurfer docker image #2

Open Nilser3 opened 10 months ago

Nilser3 commented 10 months ago

Description

Scripting

This script.py does:

To test it on Dicom data, here is a subject from PPMI project, using:

python script.py --dicom_dir Dicom_1 --dicom_out_dir Dicom_2

But I need to improve the parser of several Dicom folders, as well as preserve the entire metadata in Dicom_2.

Dockerizing

I made a first Freesurfer docker image, available in:

docker pull nilser3/freesurfer-linux-ubuntu22_x86_64-dev-20240112-88246c0_nlm:20240130.v3.0

and for test scrpit.py with Dicom_1:

docker run -v /path:/mnt -it freesurfer-linux-ubuntu22_x86_64-dev-20240112-88246c0_nlm:20240130.v3.0 python3 script.py  --dicom_dir  ../../mnt/Dicom_1  --dicom_out_dir ../../mnt/Dicom_2

(here the Processing is just a mri_convert for reslicing, just to see the functionality of this docker image)

@NathanMolinier feedback please 😊

NathanMolinier commented 10 months ago

We don't need everything to be gathered within only one script.py. Actually, for better comprehension, we should split the different functions (dicom2niftii, docker creation...)

Nilser3 commented 9 months ago

Hi @NathanMolinier , some feedbacks

Slicer 5.6.1 Visualization

image

Example of --dicom_out_dir after run script.py

NathanMolinier commented 9 months ago

Great work @Nilser3 ! Once you're done with your code, just create a Pull Request, I will check what you did !

Nilser3 commented 9 months ago

The script.py has been updated with the following:

  1. If dicom_input_dir has several subfolders, the script will run in each of these subfolders.
  2. The script will only apply to 3D anatomical images (Localizers, DTI, GRE, fMRI images are excluded, ).
  3. The script will create in dicom_output_dir the same arborescence as dicom_input_dir, only that it will contain the segmentations.

dicom_output_dir

tree dcm_seg
dcm_seg
└── PPMI
    └── 100001
        ├── 3D_T2_FLAIR
        │   └── 2020-10-07_13_51_32.0
        │       └── I1473191
        │           └── 02_Left-Cerebral-White-Matter_WMH_SynthSeg.dcm
        │           └──        .
        │           └──        .
        │           └──        .
        └── SAG_3D_MPRAGE
            ├── 2020-10-07_13_51_32.0
            │       └── I1473172
            │           └── 02_Left-Cerebral-White-Matter_WMH_SynthSeg.dcm
            │           └──        .
            │           └──        .
            │           └──        .        
            └── 2022-11-29_14_47_02.0
            │      └── I1658546
            │           └── 02_Left-Cerebral-White-Matter_WMH_SynthSeg.dcm
            │           └──        .
            │           └──        .
            │           └──        .

@NathanMolinier , Ready for a PR 😊

Nilser3 commented 9 months ago

Dockerizing

To create our container, we must have in a single folder containing :

Inside this folder we create a dockerfile with the following content.

First Docker image for freesurfer-wmhsynthseg

docker build -t freesurfer-wmhsyntheseg .

Second Docker image (add script)

Dockerfile

#  Use an Ubuntu image
FROM freesurfer-wmhsyntheseg

# Install git and other necessary dependencies
RUN apt-get update && \
    apt-get install -y git python3 python3-pip && \
    rm -rf /var/lib/apt/lists/*

# Sets the working directory to /app
WORKDIR /app
COPY . /app

# Update pip and setuptools
RUN pip3 install --upgrade pip setuptools

# Install other dependencies
RUN pip3 install -r requirements.txt
RUN pip3 install -e .

COPY run.sh /app/run.sh

# Sets the default command to run when the container starts up
ENTRYPOINT ["/app/run.sh"]

Docker image build

docker build -t registre.apps.ul-pca-pr-ul01.ulaval.ca/ul-val-prj-pim-pr/freesurfer-wmhsyntheseg:0.0.3 .

Push to Paradim Team

docker push registre.apps.ul-pca-pr-ul01.ulaval.ca/ul-val-prj-pim-pr/freesurfer-wmhsyntheseg:0.0.3

To use

docker run -v /USER_IN_PATH:/in:ro -v /USER_OUT_PATH:/out:rw registre.apps.ul-pca-pr-ul01.ulaval.ca/ul-val-prj-pim-pr/freesurfer-wmhsyntheseg:0.0.3 /in /out