MATLAB: Bwdist is computing image complement

binarybwdistgrayscaleimagesegmentationsmoothing

I have a binary image and used bwdist on the image and the resulting image was the exact compliment of the original image. I thought that bwdist would return a grayscale image based (obviously) on the distance transform. The original image is essentially an asymmetric blob of white surrounded by black, so I expected bwdist to return the same shape but with blurred borders (I need the distance transform data so just blurring the edges is not an option). Am I just expecting something that this function does not do?

Best Answer

It is probably not just the complement as you suspect. You're probably viewing it on the range [0 1] so values greater than or equal (all false values in the original) appear to be true. What is returned if you enter:
range(D(:)); %D is the output of bwdist
try viewing a slice of it over the whole range, i.e.:
imshow(D,[]);
or
imtool(D); %play with adjust contrast button.
Related Question