Skip to content

Commit

Permalink
rm in favor of just fenz
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale-Black committed Sep 20, 2023
1 parent df91282 commit fe48131
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 2,629 deletions.
284 changes: 120 additions & 164 deletions Manifest.toml

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions src/DistanceTransforms.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
module DistanceTransforms

using CUDA
using FLoops
# using FoldsCUDA
abstract type DistanceTransform end

include("./borgefors.jl")
include("./felzenszwalb.jl")
include("./maurer.jl")
include("./utils.jl")
include("./wenbo.jl")

export DistanceTransform,
transform,
transform!,

# Export chamfer.jl functions
Borgefors,

# Export maurer.jl functions
Maurer,

# Export felzenszwalb.jl functions
Felzenszwalb,

# Export utils.jl functions
boolean_indicator,

# Export wenbo.jl functions
Wenbo
boolean_indicator
end
107 changes: 0 additions & 107 deletions src/borgefors.jl

This file was deleted.

33 changes: 0 additions & 33 deletions src/felzenszwalb.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

using FLoops
using CUDA
using FoldsThreads

"""
## Felzenszwalb
Expand Down Expand Up @@ -184,34 +182,3 @@ function transform(vol::CuArray{T, 3}, tfm::Felzenszwalb; output=similar(vol, Fl
end
return output
end

function transform(img::AbstractMatrix, tfm::Felzenszwalb, ex; output=similar(img, Float32), v=ones(size(img)), z=ones(size(img) .+ 1))
# 1
@floop ex for k in CartesianIndices(@view(img[:, 1]))
@views transform(img[k,:], tfm; output=output[k,:], v=v[k,:], z=z[k,:])
end
output2 = similar(output)
# 2
@floop ex for k in CartesianIndices(@view(img[1, :]))
@views transform(output[:,k], tfm; output=output2[:,k], v=fill!(v[:,k], 1), z=fill!(z[:,k], 1))
end
# end
return output2
end

function transform(vol::AbstractArray, tfm::Felzenszwalb, ex; output=similar(vol, Float32), v=ones(size(vol)), z=ones(size(vol) .+ 1))
# 1
@floop ex for k in CartesianIndices(@view(vol[1,:,:]))
@views transform(vol[:, k], tfm; output=output[:, k], v=v[:, k], z=z[:, k])
end
output2 = similar(output)
# 2
@floop ex for k in CartesianIndices(@view(vol[:,1,:]))
@views transform(output[k[1], :, k[2]], tfm; output=output2[k[1], :, k[2]], v=fill!(v[k[1], :, k[2]], 1), z=fill!(z[k[1], :, k[2]], 1))
end
# 3
@floop ex for k in CartesianIndices(@view(vol[:,:,1]))
@views transform(output2[k, :], tfm; output=output[k, :], v=fill!(v[k, :], 1), z=fill!(z[k, :], 1))
end
return output
end
8 changes: 3 additions & 5 deletions src/maurer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@ using ImageMorphology
```julia
struct Maurer <: DistanceTransform end
```
Wrapper function for `ImageMorphology.feature_transform` and `ImageMorphology.distance_transform`. Applies a true Euclidean distance transform to the array elements and returns an array with spatial information embedded in the elements.
"""
struct Maurer <: DistanceTransform end

"""
## transform (Maurer)
## transform (Felzenszwalb)
```julia
transform(img, tfm::Maurer)
transform(img::BitArray, tfm::Maurer)
```
Wrapper function for `ImageMorphology.feature_transform` and `ImageMorphology.distance_transform`. Applies a true Euclidean distance transform to the array elements and returns an array with spatial information embedded in the elements.
Arguments
#### Arguments
- img: N-dimensional array to be transformed based on location to the nearest background (0) pixel
Citation
#### Citation
- 'A Linear Time Algorithm for Computing Exact Euclidean Distance Transforms of Binary Images in Arbitrary Dimensions' [Maurer et al., 2003] (DOI: 10.1109/TPAMI.2003.1177156)
"""
transform(img, tfm::Maurer) = distance_transform(feature_transform(Bool.(img)))
Expand Down
51 changes: 5 additions & 46 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,59 +1,18 @@
### A Pluto.jl notebook ###
# v0.19.8
using LoopVectorization

using Markdown
using InteractiveUtils

# ╔═╡ 4b4b6c39-e155-462a-b0ad-65688c949577
# ╠═╡ show_logs = false
begin
using Pkg
Pkg.activate("..")
using Revise
using PlutoUI
using Test
using CUDA
using DistanceTransforms
using LoopVectorization
end

# ╔═╡ 4db00b10-0440-4f28-bf91-01dca21847b0
TableOfContents()

# ╔═╡ 64661943-81d4-40c5-9479-fcc381544185
md"""
## Boolean Indicator
"""

# ╔═╡ 5f558b4b-d109-45d7-b2f8-fa03c0ff5db6
begin
"""
```julia
boolean_indicator(f)
```
boolean_indicator(f)
boolean_indicator(f::BitArray)
If `f` is a boolean indicator where 0's correspond to background and 1s correspond to the foreground, then mark background pixels with a large number `1e10`
If `f` is a boolean indicator where 0's correspond to background and 1s correspond to the foreground, then mark background pixels with a large number `1e10`.
Uses LoopVectorization.jl for speed up if array is `BitArray`
"""
boolean_indicator(f) = @. ifelse(f < 0.5, 1.0f10, 0.0f0)

"""
```julia
boolean_indicator(f::BitArray)
```
If `f` is a boolean indicator where 0's correspond to background and 1s correspond to the foreground, then mark background pixels with a large number `1e10`. Uses LoopVectorization.jl for speed up
"""
function boolean_indicator(f::BitArray)
f_new = similar(f, Float32)
@turbo warn_check_args=false for i in CartesianIndices(f_new)
@inbounds f_new[i] = f[i] ? 0f0 : 1f10
end
return f_new
end
end

# ╔═╡ Cell order:
# ╠═4b4b6c39-e155-462a-b0ad-65688c949577
# ╠═4db00b10-0440-4f28-bf91-01dca21847b0
# ╟─64661943-81d4-40c5-9479-fcc381544185
# ╠═5f558b4b-d109-45d7-b2f8-fa03c0ff5db6
Loading

0 comments on commit fe48131

Please sign in to comment.