bwdist is computing image complement

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?

 Accepted 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.

1 Comment

Ok I get it. I didn't realize bwdist returned unscaled values. Thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!