Open tischi opened 2 years ago
My position would be to stick on the definition of distance transform: it is defined on binary images, and hence must be applied on binary images. Also be careful about the fact the some refs define distance map for foreground pixels (distance to nearest 0-pixel), whereas some refs use the inverse (distance map for background pixels, computing distance to nearest non-zero pixel)... For example, the "bwdist" function in the Image processing toolbox of Matlab uses the second definition; that may be a problem when translating workflow from one language to another...
MorphoLibJ allows its application to non-binary images, but it considers input image is a label image, and computes in a single pair of forward-backward passes the "union" of distance maps for each binary label. About this, it is likely that a future version splits the two possibilities, and that the binary-version ones throw exception when the input is not binary (that would be more consistent with the definition).
More generally, if an operator is defined for a binary image and can be applied on a non-binary on, my recommandation would be: take care! It is either a bug, or a generalisation that has to be documented.
To complete a little bit, there are extensions of distance transforms that take into account the intensities of the pixels/voxels (I do not remember now how they are called, however...).
I think @dlegland you're thinking of this paper:
http://www.cs.cornell.edu/~dph/papers/dt.pdf
which is super badass. I had a student working on a scikit-image implementation but it got stuck in the Python -> Cython transition.
But, that's a bit off-topic: I agree with you @dlegland that one should probably take care with non-binary inputs. imho for teaching purposes, one should describe the distance transform as working on binary images.
@dlegland @jni
While one typically says that distance transforms operate on binary images, I found that both the MorpholibJ and scipy.ndimage implementations replace all non-zero pixels with their distance to the closest
0
pixel. Thus, the only pixel value with a special meaning appears to be0
, while the others can have arbitrary values. Is it fair to teach it like this to students, i.e. the input image does not need to be strictly binary?