
MedVoxelHD is CUDA C++ pytorch extension for mathemathical morphology based Hausdorff distance. Repository contain dockerfile, enviroment can be also created more conviniently with vscode remote development containers using files in this repository.
In order to build docker container one need to have NVIDIA GPU hardware and NVIDIA Container Toolkit installed link. As the example data needs also to be dowloaded and docker container e build it is advisable to have at least 30gb of space on the hard drive.
First one need to build docker container. Easiest way to execute the code is to
In order to execute the code using Python and PyTorch the python file need to be able to localize the lltm_cuda.cpp and lltm_cuda_kernel.cu files. The easiest ways to achieve it is via locating the python file in the same directory as the 2 files mentioned. In the python file the extension needs to be first loaded. For example :
from torch.utils.cpp_extension import load
lltm_cuda = load('lltm_cuda', ['lltm_cuda.cpp', 'lltm_cuda_kernel.cu'], verbose=True)
There are couple ways how to execute computations of the Hausdorff distance. The most basic one return just a single number. For example :
lltm_cuda.getHausdorffDistance(a[0,0,:,:,:], b[0,0,:,:,:], WIDTH, HEIGHT, DEPTH,0.90, torch.ones(1, dtype =bool) )
where first two entries are 3 dimensional boolean cuda pytorch tensors, that has the same shape. WIDTH, HEIGHT, DEPTH Indicate the shape of a input tensor, next is the robustness percent telling how much of the points are analyzed if set to 0.9 as above 10% of the points that are most distant from other mask will be ignored, the last entry indicates wheather we are looking for True or False voxels in most cases best to set as in example above
Additionally we have two additional functions with the same arguments:
visualize where areas that are most problematic in segmentation are present.
The example of usage is presented in the jupyter notebook file that is present in this repository and is named case_analysis.ipynb. The file is showing how to compare the image of the gold standard liver segmentation to its dilatated version. This simulates comparison of gold standard with algorithm output. Fully reproducible example with additional display of the histogram can be found on Code Ocean compute capsule link
To achieve the best performance, multiple optimizations are performed:
The most significant improvements were enabled by representing the vector of boolean values as bits in a 32-bit number. This led to:
Logo was created using generative machine learning model dall-e 3