Danielsson function
I am implementing an image segmentation algorithm, at some point I need to implement a function named "Danielsson Function" which "converts a binary image into a grayscale distance map, in which each pixel of a particle is assigned a gray level value equal to its shortest Euclidean distance from the particle boundary ".
I am not a specialist in image processing and the only way I can imagine is to use the BFS algorithm for each pixel, but it will take a long time. I couldn't find much on the internet, so I want to know if there is an optimized way to implement this or is there any Matlab / Octave function that can do such a thing?
you can simply do this using matlab's "bwdist" function as the comments mentioned in and here is a link for help if you need: Remote Binary Conversion - MATLAB bwdist
And here is the code:
I=uint8(bwdist(some_binary_image))
Be sure to use "uint8" because "bwdist" only gives you a distance matrix that has double values.
source to share