Updated by Andrey Kamaev about 13 years ago

I noticed that @distanceTransform@ distanceTransform from opencv 2.3 yields weird results, e.g the following code:

<pre><code class="python">
arr = numpy.zeros((6, 6), numpy.uint8)
(distance, labels) = cv2.distanceTransform(arr, cv2.cv.CV_DIST_L1, cv2.cv.CV_DIST_MASK_PRECISE)
print 'array\n', arr
print '\ndistance\n', distance
</code></pre>


prints:

<pre>
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.]]
</pre>


So we have weird numbers near the boundary. Other wrong results you can obtain executing the following code:

<pre><code class="python">
arr = numpy.zeros((6, 6), numpy.uint8)
arr[1:-1,1:-1] = 255

(distance, labels) = cv2.distanceTransform(arr, cv2.cv.CV_DIST_L1, cv2.cv.CV_DIST_MASK_PRECISE)
distance = distance.astype(numpy.uint8)
print 'array\n', arr
print '\ndistance\n', distance
</code></pre>


gives:

<pre>
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.]]
</pre>

Back