DistanceTransform gives wrong results (Bug #1531)
Description
I noticed that distanceTransform
from opencv 2.3 yields weird results, e.g the following code:
1arr = numpy.zeros((6, 6), numpy.uint8)
2(distance, labels) = cv2.distanceTransform(arr, cv2.cv.CV_DIST_L1, cv2.cv.CV_DIST_MASK_PRECISE)
3print 'array\n', arr
4print '\ndistance\n', distance
prints:
array [[0 0 0 0 0 0] [0 0 0 0 0 0] [0 0 0 0 0 0] [0 0 0 0 0 0] [0 0 0 0 0 0] [0 0 0 0 0 0]] distance [[ 2. 1. 1. 1. 1. 2.] [ 1. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 1.] [ 2. 1. 1. 1. 1. 2.]]
So we have weird numbers near the boundary. Other wrong results you can obtain executing the following code:
1arr = numpy.zeros((6, 6), numpy.uint8)
2arr[1:-1,1:-1] = 255
3
4(distance, labels) = cv2.distanceTransform(arr, cv2.cv.CV_DIST_L1, cv2.cv.CV_DIST_MASK_PRECISE)
5distance = distance.astype(numpy.uint8)
6print 'array\n', arr
7print '\ndistance\n', distance
gives:
array [[ 0 0 0 0 0 0] [ 0 255 255 255 255 0] [ 0 255 255 255 255 0] [ 0 255 255 255 255 0] [ 0 255 255 255 255 0] [ 0 0 0 0 0 0]] distance [[ 8192. 8192. 8192. 8192. 8192. 8192.] [ 8192. 8192. 8192. 8192. 8192. 8192.] [ 8192. 8192. 8192. 8192. 8192. 8192.] [ 8192. 8192. 8192. 8192. 8192. 8192.] [ 8192. 8192. 8192. 8192. 8192. 8192.] [ 8192. 8192. 8192. 8192. 8192. 8192.]]
Associated revisions
fixed bug #1531. added separate distanceTransformWithLabels function that returns labels, since normally the labels are not needed.
History
Updated by pzo - about 13 years ago
Some update:
I've tested similar code using c++ API and I noticed that I have the same wrong results only when I execute the version of distanceTransform
that returns labels as well void distanceTransform(InputArray src, OutputArray dst, OutputArray labels, int distanceType, int maskSize)
The other version w/o labels works fine void distanceTransform(InputArray src, OutputArray dst, OutputArray labels, int distanceType, int maskSize)
.
It looks like python wrapper always executes the latter buggy one.
Updated by Vadim Pisarevsky about 13 years ago
fixed in r7206
Updated by Vadim Pisarevsky about 13 years ago
- Status changed from Open to Done
- (deleted custom field) set to fixed
Updated by Andrey Kamaev about 13 years ago
- Target version set to 2.4.0
- Description changed from I noticed that distanceTransform from opencv 2.3 yields weird results, e.g th... to I noticed that @distanceTransform@ from opencv 2.3 yields weird results, e.g ... More