Skip to main content

Distance Map library

Project description


Python Distance Map library

For a N-dimension (2 ≤ N ≤ 3) binary matrix, return the corresponding distance map. For each pixel, the value is equal to the minimum distance to a "positive" pixel. Due to the way I plan to use this library, the implementation is in reality articulate over a list of positive points positions and not a binary matrix.

Δ = distance to nearest positive point
α = a user defined function (ℝ+ → ℝ+) (default : x ↦ x)
Ω = the maximum value

P_result(x, y) = min(α(Δ), Ω)


Example 1 Example 2


Input is a list of positive points

distance_map(input.shape, points)

Input is binary (boolean) matrix


Input is a list of positive points and you want to use custom arguments

distance_map(input.shape, points, distance="manhattan", beta=15.0, alpha="square")


  • Distance
    • euclidean
    • manhattan
  • Alpha
    • identity (x ↦ x)
    • square (x ↦ x*x)
    • linear (x ↦ A*x + B)
      • use set_a(a) and def set_b(b) to change A and B values


The following tests has been made on a laptop with an Intel Core i7-7700HQ and 24Go of RAM.

Test Time distance_map Time distance_map_from_binary_matrix
2D 1024 x 1024 image with 10 positive points 8ms 11ms
2D 1024 x 1024 image with 5 positive points 5ms 9ms
3D 128 x 128 x 128 image with 10 positive points 61ms 148ms


This library is inspired for use as in the following paper.

N. Xu, B. Price, S. Cohen, J. Yang and T. Huang
"Deep Interactive Object Selection"
2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR)
Las Vegas, NV, 2016, pp. 373-381
doi: 10.1109/CVPR.2016.47

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for distance-map, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size distance_map-1.0.1-py3-none-any.whl (5.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size distance-map-1.0.1.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page