/BCM-Net

source code for our work "Bilateral Context Modeling for Residual Coding in Lossless 3D medical image compression"

Primary LanguagePython

Source code for our work "Bilateral Context Modeling for Residual Coding in Lossless 3D Medical Image Compression"

Overview of BCM-Net


Preparation

Download Data and Pretrained Models

Download Test Dataset

  1. Download MRNet test dataset from MRNet.
  2. Download MosMedData test dataset from Kaggle.
  3. Download TRABIT test dataset from Kaggle.
  4. Move the dataset to {Data_Path}, where {Data_Path} is the directory to store data. The directory should be organized like:
{Data_Path}
   - MRNet-v1.0
      - valid
         - axial
            - 1130.npy
            - ...
         - coronal
            - 1130.npy
            - ...
         - sagittal
            - 1130.npy
            - ...
   - Mosmed_COVID-19_CT
      - CT-3
         - study_1064.nii
         - ...
   - TRABIT
      - test
         - mri_00539274.nii
         - ...

Download Pretrained Models

Download pre-trained models from Google Driver.

Install Docker and NVIDIA-Container-Toolkit on Ubuntu

You can refer to the following documents to install Docker and NVIDIA-Container-Toolkit on Ubuntu.

  1. Install Docker
  2. Install NVIDIA-Container-Toolkit

Run Docker Container

  1. go to the project directory.
  2. create a docker image.
    docker build -t medical .
  3. create a docker container and run it.
    docker run -it --name="BCM-Net" --gpus all --runtime=nvidia \
     -v {Code_Path}:/home/Code 
     -v {Models_Path}:/home/Models
     -v {Data_Path}:/home/Data \
     -v {Experiment_Path}:/home/Experiment \
     medical:latest
    
    • {Code_Path} denotes the project directory path
    • {Models_Path} denotes the model directory path
    • {Data_Path} denotes the data directory path
    • {Experiment_Path} denotes the experimental directory path to save results

Compile traditional video codec VTM-15.0

The following commands should be executed in the Docker container.

  1. go to the VTM folder.
    cd /home/VVCSoftware_VTM
  2. compile VTM codec which supports 8/10bit input.
    mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && make -j
  3. rename the compiled codec.
    mv ../bin/EncoderAppStatic /home/VVC_Encoder_8bit && mv ../bin/DecoderAppStatic /home/VVC_Decoder_8bit
  4. set the macro JVET_R0351_HIGH_BIT_DEPTH_ENABLED to 1 to support 16-bit input.
    nano ./source/Lib/CommonLib/TypeDef.h
    # then change line 84 and save the file
  5. compile VTM codec which supports 16bit input.
    make clean && cmake .. -DCMAKE_BUILD_TYPE=Release && make -j
  6. rename the compiled codec.
    mv ../bin/EncoderAppStatic /home/VVC_Encoder_16bit && mv ../bin/DecoderAppStatic /home//VVC_Decoder_16bit

Test Our Method

The following commands should be executed in the Docker container.

🐛 Please modify the torch source file according to this PR before the test.

Test on MRNet

Test on the axial subset

cd /home/Code && python3 TestMRNet.py --mr_net_root /home/Data/MRNet-v1.0/valid/axial --save_directory /home/Experiment/TestAxial \
                                      --lossy_encoder_path /home/VVC_Encoder_8bit \
                                      --lossy_decoder_path /home/VVC_Decoder_8bit \
                                      --lossy_cfg_path /home/VVCSoftware_VTM/cfg/encoder_randomaccess_vtm_gop16.cfg /home/VVCSoftware_VTM/cfg/per-class/classSCC.cfg \
                                      --qp 37 --checkpoints /home/Models/MRNet/Axial.pth --gpu

Test on the coronal subset

cd /home/Code && python3 TestMRNet.py --mr_net_root /home/Data/MRNet-v1.0/valid/coronal --save_directory /home/Experiment/TestCoronal \
                                      --lossy_encoder_path /home/VVC_Encoder_8bit \
                                      --lossy_decoder_path /home/VVC_Decoder_8bit \
                                      --lossy_cfg_path /home/VVCSoftware_VTM/cfg/encoder_randomaccess_vtm_gop16.cfg /home/VVCSoftware_VTM/cfg/per-class/classSCC.cfg \
                                      --qp 37 --checkpoints /home/Models/MRNet/Coronal.pth --gpu

Test on the sagittal subset

cd /home/Code && python3 TestMRNet.py --mr_net_root /home/Data/MRNet-v1.0/valid/sagittal --save_directory /home/Experiment/TestSagittal \
                                      --lossy_encoder_path /home/VVC_Encoder_8bit \
                                      --lossy_decoder_path /home/VVC_Decoder_8bit \
                                      --lossy_cfg_path /home/VVCSoftware_VTM/cfg/encoder_randomaccess_vtm_gop16.cfg /home/VVCSoftware_VTM/cfg/per-class/classSCC.cfg \
                                      --qp 37 --checkpoints /home/Models/MRNet/Sagittal.pth --gpu                 

Test on MosMedData

cd /home/Code && python3 TestMosMedData.py --mosmed_root /home/Data/Mosmed_COVID-19_CT/CT-3 --save_directory /home/Experiment/TestMosMedData \
                                      --lossy_encoder_path /home/VVC_Encoder_16bit \
                                      --lossy_decoder_path /home/VVC_Decoder_16bit \
                                      --lossy_cfg_path /home/VVCSoftware_VTM/cfg/encoder_randomaccess_vtm_gop16.cfg /home/VVCSoftware_VTM/cfg/per-class/classSCC.cfg \
                                      --qp 17 --checkpoints /home/Models/MosMedData/MosMedData.pth --gpu \
                                      --bit_depth 16                       

Test on TRABIT

cd /home/Code && python3 TestTRABIT.py --trabit_root /home/Data/TRABIT2019_MRI/test --save_directory /home/Experiment/TestTRABIT \
                                      --lossy_encoder_path /home/VVC_Encoder_16bit \
                                      --lossy_decoder_path /home/VVC_Decoder_16bit \
                                      --lossy_cfg_path /home/VVCSoftware_VTM/cfg/encoder_randomaccess_vtm_gop16.cfg /home/VVCSoftware_VTM/cfg/per-class/classSCC.cfg \
                                      --qp 0 --checkpoints /home/Models/TRABIT/TRABIT.pth --gpu \
                                      --bit_depth 16

Acknowledgment

❤️❤️❤️ This work is implemented based on the following projects. We really appreciate their wonderful open-source work!

Citation

@ARTICLE{10478821,
  author={Liu, Xiangrui and Wang, Meng and Wang, Shiqi and Kwong, Sam},
  journal={IEEE Transactions on Image Processing}, 
  title={Bilateral Context Modeling for Residual Coding in Lossless 3D Medical Image Compression}, 
  year={2024},
  volume={},
  number={},
  pages={1-1},
  doi={10.1109/TIP.2024.3378910}}