Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions dilation.jl

This file was deleted.

22 changes: 22 additions & 0 deletions src/Batching_channeling/batching_channeling.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ITKIOWrapper

function batching_channeling!(tensor5D, input_images, number_of_batches, number_of_channels)
expected_length = number_of_batches * number_of_channels
if length(input_images) != expected_length
error("Input image count mismatch: expected $(expected_length), got $(length(input_images)).")
end

reshaped_input_images = reshape(input_images, (number_of_batches, number_of_channels))

for batch in 1:number_of_batches
for channel in 1:number_of_channels
image = reshaped_input_images[batch, channel]
metadata = load_spatial_metadata(image)
voxel_data = load_voxel_data(image, metadata)
arr = voxel_data.dat
arr_perm = permutedims(arr, (3, 1, 2)) # (depth, height, width)
tensor5D[batch, channel, :, :, :] .= arr_perm
end
end
return tensor5D
end
8 changes: 4 additions & 4 deletions src/Morphology_operations/dilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using KernelAbstractions
# Description:
The kernel performs binary dilation on a 5D tensor of shape
[batch_size, channels, depth, height, width] using a given
structuring element. Each voxel is checked against its neighborhood
structuring element of shape [depth, height, width]. Each voxel is checked against its neighborhood
as defined by the structuring element.

"""
Expand All @@ -24,9 +24,9 @@ as defined by the structuring element.
for p in 1:size(struct_element)[3]
# actual coordinates in the 3D input image within the current batch and channel slice
# that the structuring element is currently influencing
ni = i + m - offset_h - 1
nj = j + n - offset_w - 1
nk = k + p - offset_d - 1
nk = k + m - offset_d -1
ni = i + n - offset_h - 1
nj = j + p - offset_w - 1

if 1 <= nk <= size(input)[3] && 1 <= ni <= size(input)[4] &&
1 <= nj <= size(input)[5]
Expand Down
50 changes: 50 additions & 0 deletions src/Morphology_operations/erosion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using KernelAbstractions

@kernel function erode_kernel!(output, input, struct_element)
I = @index(Global, Cartesian)
b, c, k, i, j = Tuple(I)

offset_d = div(size(struct_element)[1], 2)
offset_h = div(size(struct_element)[2], 2)
offset_w = div(size(struct_element)[3], 2)

if b <= size(input)[1] && c <= size(input)[2] && k <= size(input)[3] &&
i <= size(input)[4] && j <= size(input)[5]

result = true

for m in 1:size(struct_element)[1]
for n in 1:size(struct_element)[2]
for p in 1:size(struct_element)[3]
nk = k + m - offset_d - 1
ni = i + n - offset_h - 1
nj = j + p - offset_w

if 1 <= nk <= size(input)[3] && 1 <= ni <= size(input)[4] &&
nj <= size(input)[5]
if struct_element[m, n, p] == 1 && input[b, c, nk, ni, nj] == 0
result = false
break
end
else
# Treat out-of-bounds as 0 (zero-padding erosion)
if struct_element[m, n, p] == 1
result = false
break
end
end
end
if !result; break; end
end
if !result; break; end
end
@inbounds output[b, c, k, i, j] = result ? 1 : 0
end
end

function erode!(output, input, struct_element)
backend = get_backend(input)
kernel! = erode_kernel!(backend)
kernel!(output, input, struct_element, ndrange=size(output))
return output
end