Skip to content

RiccardoBiondi/FemurSegmentation

Repository files navigation

Femur Segmentation

A simple pipeline for the segmentation of femur CT scan based on Graph Cut.

Authors Project Build Status License Code Quality
R.Biondi
D. Dall'Olio
FemurSegmentation Ubuntu CI
Windows CI
license Codacy Codacy Badge
Codebeat codebeat badge

Appveyor Build status

Table of Contents

  1. Introduction
  2. Usage
  3. Contribute
  4. License
  5. Authors
  6. Acknowledgments
  7. Citation
  8. References

Introduction

Prerequisites

Supported python versions: Python version

Supported c++ compilers: g++ compiler clang compiler MinGW compiler

Installation

Clone the repository:

git clone https://github.com/RiccardoBiondi/FemurSegmentation
cd FemurSegmentation

If you are using conda, create and activate the environment:

conda env create -f itk_env.yaml
conda env activate itk

Or, if you are using pip, install the required packages:

python -m pip install -r requirements.txt

Now you are ready to build the package:

python setup.py develop --user

Debian 12 bookworm: I personally had some problems on Debian 12. Installing with conda via the yaml file led to error when trying to import itk, solved by installing via pip. Then, the error "longintrepr.h no such file or directory" from cython was raised when running setup.py: solved by using python version 3.10. Complete set of commands:

conda create --name itk python=3.10
conda activate itk
python -m pip install -r requirements.txt
python setup.py develop --user

Testing

We have provide a test routine in test directory. This routine use:

  • pytest >= 3.0.7

  • hypothesis >= 4.13.0

Please install these packages to perform the test. You can run the full set of test with:

  python -m pytest

Getting Started

Now we will see how to perform the automated and semi-automated segmentation.

Make sure to add /FemurSegmentation/lib to your python library before running.

On Ubuntu like os:

export PYTHONPATH=$PYTHONPATH:~/FemurSegmentation/lib/

or for windows users(from PowerShell):

$env:PYTHONPATH="C:\path\to\FemurSegmentation\lib\"

Prepare Data

This script will process one leg at a time. Firstly we have to split the whole CT scan into left and right leg. split_image script will perform this step:

  python split_image.py --input='path/to/input/image' --output='./output/file/name'

You can also provide the ground truth segmentation to format the labels for each leg:

  python split_image.py --input='/path/to/input/image' --output='/path/to/output/file/name' --label='/path/to/image/labels'

Automated Segmentation

Now you can segment one leg at time by running:

python run_automated_segmentation.py --input='/path/to/input/directory/ --output='/path/to/output/directory'

Input should be the path to a directory containing CT femur scans in .nrrd extension, already splitted in half so that only one leg is present in each CT scan. All the files of input directory will be processed. The output directory is the directory in which the 3D segmentation corresponding to each input file will be saved. For any support write to federico.magnani9@unibo.it.

Semi-Automated Segmentation

To run the semi automated segmentation, you have to provide the hard constrains. To do so, you have to manually label six or seven slices of the whole scan.

Label Legend:

  • 0: No label
  • 1: Femur
  • 2: Background (Soft tissues, non-femur bones)

notes Be careful on the hip-joint region

To achieve this purpose, you can use 3DSlicer sofrtware.

note The hard constrain mask must have the same size of the original image.

Now you are ready to perform the segmentation:

python run_semiautomated_segmentation.py --input='/path/to/input/file/ --output='/path/to/output/file.nrrd' --init='/path/to/init/hard/constrains'

Smoothing

Optionally it is possible to apply 3 different smoothing after the segmentation. These smoothing are:

  • gaussian
  • open_close
  • shrink_grow

To specify the ind of smoothing run:

python run_semiautomated_segmentation.py --input='/path/to/input/file/ --output='/path/to/output/file.nrrd' --init='/path/to/init/hard/constrains' --smoothing='gaussian'

the command --smooth_size allows to specify the kernel size of the smoothing operations

Snakemake

If you have not installed snakemake, you can find the instruction here. The snalemake pipeline allows you to split a lower limb CT scan into right and left legs and perform an automated femur segmentation in a multi-subject segmentation framework. All the subjects must be organized as follows

base_dir | | patient1| | patient1_[TAG] | patient2| | patient2_[TAG]

where patient1 (or patient 2) is the patient ID. patient_[TAG] is a folder containing the DICOM. As default [TAG] is "CTData", if you want to use a different tag, edit the TAG attibute in the config.yml of change it from command line.

Now you can execute the pipeline by typing from command line:

snakemake --cores 1 --config base_dir='/path/to/base_dir'

The result will be the following:

base_dir | | patient1| | patient1_[TAG] patient1_R.nrrd patient1_L.nrrd patient1_seg_R.nrrd patient1_seg_L.nrrd

        |
        patient2|
                |
                patient2_[TAG]
                patient2_R.nrrd
                patient2_L.nrrd
                patient2_seg_R.nrrd
                patient2_seg_L.nrrd

where the files _R and _L are the images corresponding to the right and left leg, and the _seg_R, _seg_L the one corresponding to the right and left segmentation

Contribute

Any contribution is more than welcome. Just fill an issue or a pull request and we will check ASAP!

See here for further informations about how to contribute with this project.

License

Authors

Acknowledgments

Citation

@misc{FemurSegmentation,
  author = {Biondi, Riccardo and Dall'Olio, Daniele and Curti, Nico and Castellani, Gastone},
  title = {A graph Cut Approach for Femur Segmentation},
  year = {2021},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/RiccardoBiondi/FemurSegmentation}},
}

References

[1] Krčah, M., Székely, G., Blanc, R. Fully automatic and fast segmentation of the femur bone from 3D-CT images with no shape prior 2011 IEEE International Symposium on Biomedical Imaging: From Nano to Macro, Chicago, IL, 2011, pp. 2087-2090. doi

[2] Bryce A. Besler, Andrew S. Michalski, Michael T. Kuczynski, Aleena Abid, Nils D. Forkert, Steven K. Boyd Bone and joint enhancement filtering: Application to proximal femur segmentation from uncalibrated computed tomography datasets, Medical Image Analysis 2021 Medical Image Analysis, Volume 67 ISSN 1361-8415. doi

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages