imeka / ndarray-ndimage

Multidimensional image processing for ndarray
Apache License 2.0
14 stars 2 forks source link

Morphology and Kernel #6

Closed nilgoyette closed 1 year ago

nilgoyette commented 2 years ago

We're currently using the Kernel3d enum (Star and Full) as the only choices for kernels.

The advantage is that we're quite fast because we know exactly where the "weights" are. This makes it possible to hardcode the conditions. For example, we're around 5 times faster than SciPy in morphology operations.

While this is nice, the problem is that the user can't choose it's own special kernel. I have personally never seen a non-start or non-full kernel choice in the wild, but it could happen.

Ideas:

In brief, I want to keep being faster than SciPy and add all kernel choices. I tested an algo that offers more choices.

// Indices for the Star kernel
let indices = vec![(0, 1, 1), (1, 0, 1), (1, 1, 0), (1, 1, 1), (1, 1, 2), (1, 2, 1), (2, 1, 1)];
// Erosion
Zip::from(mask.windows((3, 3, 3)))
    .map_assign_into(zone, |w| !indices.iter().any(|&idx| !w[idx]));
// Dilation
Zip::from(mask.windows((3, 3, 3)))
    .map_assign_into(zone, |w| indices.iter().any(|&idx| w[idx]));

It's not too bad. We're still a little faster than SciPy and we're accepting all kernels. I just wonder if there's a way to keep our advantages :)

nilgoyette commented 1 year ago

This has been fixed in v2.x.