Giter Site home page Giter Site logo

rg2 / deepfluorolabeling-ipcai2020 Goto Github PK

View Code? Open in Web Editor NEW
74.0 3.0 12.0 7.04 MB

Code and data for the "annotation" component of the IPCAI 2020 paper: "Automatic Annotation of Hip Anatomy in Fluoroscopy for Robust and Efficient 2D/3D Registration." https://arxiv.org/abs/1911.07042 or https://doi.org/10.1007/s11548-020-02162-7

License: Other

Python 100.00%
landmark-detection semantic-segmentation registration 2d-3d-registration x-ray-navigation orthopaedics pytorch u-net convolutional-neural-networks fluoroscopy

deepfluorolabeling-ipcai2020's Introduction

DeepFluoroLabeling-IPCAI2020

Example Ground Truth Annotations

This repository contains implementation details for automatically annotating fluoroscopy of the hip. Higher-level information, including clinical motivations, prior works, algorithmic details, applications to 2D/3D registration, and experimental details, may be found in the IPCAI 2020 paper "Automatic Annotation of Hip Anatomy in Fluoroscopy for Robust and Efficient 2D/3D Registration," available at https://arxiv.org/abs/1911.07042 or https://doi.org/10.1007/s11548-020-02162-7. The primary contents of this repository are:

  • Links to the annotated dataset of actual hip fluoroscopy used for training/testing,
  • Documentation and examples for using the dataset,
  • Python code for training and testing the proposed models.

The dataset consists of CT, fluoroscopy, and derived data from six lower torso cadaveric specimens.

Implementations of the registration algorithms, both offline and online, are provided in the Regi2D3D-IPCAI2020 repository.

For any questions or feature requests, please open an issue or send an email to Rob ([email protected]).

We hope that this code and data will be useful in the development of new computer-assisted capabilities that leverage fluoroscopy. If you have used the code or dataset, we kindly ask that you cite our paper:

Grupp, Robert B., et al. "Automatic annotation of hip anatomy in fluoroscopy for robust and efficient 2D/3D registration." International Journal of Computer Assisted Radiology and Surgery (2020): 1-11.
----------------------------------------------------------------------
@article{grupp2020automatic,
  title={Automatic annotation of hip anatomy in fluoroscopy for robust and efficient {2D}/{3D} registration},
  author={Grupp, Robert B and Unberath, Mathias and Gao, Cong and Hegeman, Rachel A and Murphy, Ryan J and Alexander, Clayton P and Otake, Yoshito and McArthur, Benjamin A and Armand, Mehran and Taylor, Russell H},
  journal={International Journal of Computer Assisted Radiology and Surgery},
  pages={1--11},
  publisher={Springer}
}

Annotations

Segmentation labels are assigned to the following skeletal structures:

  • Left Hemipelvis (1)
  • Right Hemipelvis (2)
  • Vertebrae (3)
  • Upper Sacrum (4)
  • Left Femur (5)
  • Right Femur (6)

All other pixels should be assigned to background (0). Label values are consistent across 2D and 3D segmentations (e.g. the left femur is labeled 5 in both the 3D segmentation and 2D segmentation). We did not attempt to model the lower sacrum, since it is a difficult shape to characterize in 3D and 2D and does not aid our intended applications.

The following bilateral anatomical landmarks are considered:

  • ASIS: Anterior Superior Iliac Spine
  • FH: Femoral Head Center
  • GSN: Greater Sciatic Notch
  • IOF: Interior Obturator Foramen
  • MOF: Medial Obturator Foramen
  • SPS: Superior Pubis Symphysis
  • IPS: Inferior Pubis Symphysis

Since each landmark is bilateral, a "-l" is appended to the name to indicate left and a "-r" is appended to the name to indicate right. For example, "FH-r" is the right femoral head center.

The 3D landmarks and bone structures are shown below: 3D Annotations

Datasets

You can access the annotated dataset in full-resolution here in HDF5 format (2.5 GB). However, this data was preprocessed prior to training and testing of the models. Several preprocessed versions of the dataset, ready for training/testing are also available in HDF5 format:

These files are graciously hosted by the JHU Data Archive, with a full listing of the dataset contents and metadata provided here.

Documentation on the organization of data within each HDF5 is found here. Some example code for using these files is provided in examples_dataset. Examples of using the preprocessed datasets for training/testing are in train_test_code.

The specimen numbers (1-6) from the paper map to the following specimen IDs in the full dataset files:

  • 1 --> 17-1882
  • 2 --> 18-1109
  • 3 --> 18-0725
  • 4 --> 18-2799
  • 5 --> 18-2800
  • 6 --> 17-1905

The preprocessing steps consist of cropping 50 pixels from each border to remove collimater effects, log transforming the projection data, rotation to ensure patient is "up," and downsampling.

Log transforming uses the Beer-Lambert law to approximately convert pixels from measured X-ray intensities to line integrals of attenuation units. Intuitively, this maps "bone is dark" to "bone is bright."

Some of the projections need to be rotated 180 degrees to have the patients oriented "up," which places the superior aspect of the hip at the top of the image and the inferior aspect of the hip at the bottom of the image. The need for this rotation is automatically determined from metadata present in the DICOM files produced by the C-arm.

The downsampling factors indicate the amount of downsampling in each 2D dimension. Experiments in the IPCAI paper used 8x downsampling. Although the intensity projections are directly downsampled in 2D, the 2D segmentations are downsampled by ray-casting against a smaller detector grid. Directly downsampling the full-resolution 2D segmentations should also work and may yield smoother ground truth labelings.

Original files for the CT scans and 2D fluoroscopy files are part of the dataset from our TBME paper, and are available here.

Training/Testing Code

Python code for training and testing the models is found in train_test_code. The Readme also provides details on the Python environment and example commands for training/testing and examining the data. Users that do not have access to a reasonably powered GPU may use this Google Colab notebook to complete the training/testing process.

Applications to 2D/3D Registration

In the IPCAI 2020 companion paper, we use these annotations to perform automatic registrations of the pelvis and each femur. The following YouTube video shows several examples: https://youtu.be/5AwGlNkcp9o. Implementations of these registration strategies are provided in the Regi2D3D-IPCAI2020 repository

Licensing

The datasets are provided under a CC BY-NC 4.0 license (Attribution and Noncommercial). The Python code in this repository is provided under a GPLv3 license.

deepfluorolabeling-ipcai2020's People

Contributors

rg2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

deepfluorolabeling-ipcai2020's Issues

How to compute 2D and 3D landmarks

Hi Robert, I am curious how the locations for the 3D vol-landmarks the 2D gt-landmarks are generated. Are these values in the CTs / fluoroscopy images that we can identify by pixel intensity?

What are the exact preprocessing steps for the fluoroscopy images?

I am trying to recapitulate the preprocessing steps you mention in the README:

The preprocessing steps consist of cropping 50 pixels from each border to remove collimator effects, log transforming the projection data, rotation to ensure patient is "up," and downsampling.

I can't get the log transform step quite right. Here's what I've tried so far:

import h5py
import matplotlib.pyplot as plt
import torch
from torchvision.transforms.functional import center_crop, resize

fullres = h5py.File("ipcai_2020_full_res_data.h5", "r")
downsam = h5py.File("data/ipcai_2020_ds_8x.h5", "r")

# Full-res image
idx = 20
img = fullres[f"17-1882/projections/{idx:03d}/image/pixels"][:]

# Processing the full-res image
img_ = torch.from_numpy(img)
img_ = center_crop(img_, [1536-50, 1536-50])  # Crop 50 pixels from each border to remove collimator effects
img_ = -img_.log()  # Log-transform the projection data
img_ = resize(img_.unsqueeze(0).unsqueeze(0), [180, 180], antialias=True).squeeze()  # Downsample

# Get the preprocessed image
dsimg = downsam["01/projs"][:]

plt.figure(constrained_layout=True, dpi=300, figsize=(10, 2.5))
plt.subplot(131)
plt.imshow(img, cmap="gray")
plt.colorbar()
plt.title("Full-res image")
plt.subplot(132)
plt.imshow(img_, cmap="gray")
plt.colorbar()
plt.title("My processed image")
plt.subplot(133)
plt.imshow(dsimg[idx], cmap="gray")
plt.colorbar()
plt.title("Your preprocessed image")
plt.show()

which produces
download

I'm guessing you've implemented the log transform differently?

Thank you for taking the time to organize and document this dataset so thoroughly! It's a joy to work with.

how to get the parameter? (cam-to-pelvis-vol)

Hello. I am trying to create a custom dataset following the format of ipcai_2020_full_res_data.h5. I want to obtain the cam-to-pelvis-vol parameter, but I am having difficulty understanding its meaning.

Initially, I thought it was the transformation matrix from the source to the volume when generating DRRs. However, upon examining the data, I found that the values differ internally for different regions even for a single DRR.

What does this parameter mean? And how can I obtain it? I would appreciate it if you could explain. Thank you.

TypeError: 'float' object is not iterable

Hi,

Thanks for providing such a great code!
I am passing the following command
python -u train.py ipcai_2020_ds_8x.h5 --train-pats 2,3,4,5,6 --num-classes 7 --init-lr 0.1 --momentum 0.9 --unet-batch-norm --unet- no-max-pool --unet-img-dim 192 --unet-num-lvls 6 --batch-size 5 --max-num-epochs 500 --unet-init-feats-exp 5 --wgt-decay 0.0001 --data-aug --unet-padding --nesterov --checkpoint-net yy_check_net.pt --checkpoint-freq 100 --use-lands --best-net yy_best_net.pt --lr-sched plateau --train -valid-split 0.85 --train-loss-txt yy_train_loss.txt --valid-loss-txt yy_valid_loss.txt --heat-coeff 0.5
When running the training code, it throws an error

num. lands read from file: 14
initializing training dataset/dataloader
split dataset into train/validation
  randomly splitting all complete tensors into training/validation...
Length of training dataset: 217
Length of validation dataset: 38
creating network
moving network to device...
creating loss function
  Dice + Heatmap Loss...
creating SGD optimizer and LR scheduler
Start Training...
Epoch: 000
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py:1041: UserWarning: Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead
  "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
Traceback (most recent call last):
  File "train.py", line 399, in <module>
    for (i, data) in enumerate(train_dl, 0):
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 521, in __next__
    data = self._next_data()
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
    return self._process_data(data)
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
    data.reraise()
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torch/_utils.py", line 425, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/***/Downloads/DeepFluoroLabeling-IPCAI2020-2020.03.17/train_test_code/dataset.py", line 230, in __getitem__
    A_inv = TF._get_inverse_affine_matrix(center_of_rot, rot_ang, (trans_x, trans_y), scale_factor, shear)
  File "/home/***/anaconda3/envs/re/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 903, in _get_inverse_affine_matrix
    sx, sy = [math.radians(s) for s in shear]
TypeError: 'float' object is not iterable

Can you help me?

Thanks in advance,
Crack

Projection parameters

Hi Robert, sorry to bother again but I am having doubts about my understanding of some of the parameters.

My rough understanding is that the extrinsic matrix, in general, gives the position/orientation of the camera capturing an image. That is why it would make sense in my head to have one such matrix for each projection.

In your dataset there seems to be a global extrinsic matrix to shift to camera space, and 3 different matrices to shift into volume space (whether pelvis or either femur). Could you please give a brief explanation as to how you obtained these matrices, what the global one represents, and where the shift takes us (is it the center of the volume? one of the corners?). Trying to generalise to some other data has proven a little difficult for me..

Thank you.

Intrinsic matrix

Hi Robert, thank you for this code and especially dataset, it's incredibly thorough and very useful!

However I have one question, how do you generate the "intrinsic" matrix found in the "proj-params" section of the dataset? From what I understand, you can obtain the extrinsic matrix using information provided with most CT files, however I have not found how to extract or simulate the intrinsic matrix using a different set of data. Is that directly related to the specific C-arm or capture device? Would one be able to get this information just from a DICOM series? I understand this may not be your expertise but if you had an insight on that it'd be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.