Skip to content

Commit

Permalink
Merge pull request #41 from masadcv/euclidean-impl
Browse files Browse the repository at this point in the history
Fix bug in local Euclidean distance calculation for fast implementation
  • Loading branch information
masadcv authored Feb 20, 2023
2 parents e2be5bd + 6bd1845 commit 7101eb3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions FastGeodis/fastgeodis.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ torch::Tensor generalised_geodesic2d_cuda(
torch::Tensor generalised_geodesic3d_cuda(
const torch::Tensor &image,
const torch::Tensor &mask,
const std::vector<float> &spacing,
std::vector<float> spacing,
const float &v,
const float &l_grad,
const float &l_eucl,
Expand All @@ -64,7 +64,7 @@ torch::Tensor generalised_geodesic2d_cpu(
torch::Tensor generalised_geodesic3d_cpu(
const torch::Tensor &image,
const torch::Tensor &mask,
const std::vector<float> &spacing,
std::vector<float> spacing,
const float &v,
const float &l_grad,
const float &l_eucl,
Expand Down
7 changes: 5 additions & 2 deletions FastGeodis/fastgeodis_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void geodesic_frontback_pass_cpu(
ld += float(std::abs(h_i - 1)) * spacing[1];
ld += float(std::abs(w_i - 1)) * spacing[2];

local_dist[h_i * 3 + w_i] = ld;
local_dist[h_i * 3 + w_i] = sqrt(ld);
}
}

Expand Down Expand Up @@ -342,13 +342,16 @@ void geodesic_frontback_pass_cpu(
torch::Tensor generalised_geodesic3d_cpu(
const torch::Tensor &image,
const torch::Tensor &mask,
const std::vector<float> &spacing,
std::vector<float> spacing,
const float &v,
const float &l_grad,
const float &l_eucl,
const int &iterations
)
{
// square spacing with transform
std::transform(spacing.begin(), spacing.end(), spacing.begin(), spacing.begin(), std::multiplies<float>());

torch::Tensor image_local = image.clone();
torch::Tensor distance = v * mask.clone();

Expand Down
7 changes: 5 additions & 2 deletions FastGeodis/fastgeodis_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void geodesic_frontback_pass_cuda(
ld += float(std::abs(h_i - 1)) * spacing[1];
ld += float(std::abs(w_i - 1)) * spacing[2];

local_dist[h_i * 3 + w_i] = ld;
local_dist[h_i * 3 + w_i] = sqrt(ld);
}
}
// copy local distances to GPU __constant__ memory
Expand Down Expand Up @@ -582,13 +582,16 @@ void geodesic_frontback_pass_cuda(
torch::Tensor generalised_geodesic3d_cuda(
const torch::Tensor &image,
const torch::Tensor &mask,
const std::vector<float> &spacing,
std::vector<float> spacing,
const float &v,
const float &l_grad,
const float &l_eucl,
const int &iterations
)
{
// square spacing with transform
std::transform(spacing.begin(), spacing.end(), spacing.begin(), spacing.begin(), std::multiplies<float>());

torch::Tensor image_local = image.clone();
torch::Tensor distance = v * mask.clone();

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ def get_extensions():

setup(
name="FastGeodis",
version="1.0.0",
version="1.0.1",
description="Fast Implementation of Generalised Geodesic Distance Transform for CPU (OpenMP) and GPU (CUDA)",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/masadcv/FastGeodis",
author="Muhammad Asad",
author_email="[email protected]",
author_email="[email protected]",
license="BSD-3-Clause License",
classifiers=[
"License :: OSI Approved :: BSD License",
Expand Down

0 comments on commit 7101eb3

Please sign in to comment.