0

I am looking for a python implementation of distance transform of a given binary image. No existing library code is to be used.

This is what I have done so far -

#function to find EUCLIDIAN distance to nearest wall from current cell
def find_len_to_nearest_wall(img,row,col):

#read binary image (white(walls) - [255,255,255], black(free space) - [0,0,0])
img = cv2.imread("4_1_map.png")
img_new = [[0 for n in len(img[0])] for n2 in len(img)]
#distance transforming...
for row in img:
    for col in row:
        if img[row][col][0] == 255:
            num = numpy.uint8(255)
        else:
            num = numpy.uint8(find_len_to_nearest_wall(img,row,col))
        img_new[row][col] = [num,num,num]

How do I start writing the function to find length to nearest wall/obstacle

kaysri
  • 1
  • 3
  • 2
    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [on topic](http://stackoverflow.com/help/on-topic) and [how to ask](http://stackoverflow.com/help/how-to-ask) apply here. StackOverflow is not a coding or tutorial service. – Prune Dec 22 '16 at 18:56
  • 1
    Specifically, 'I am having a problem' is not a question. What problem? What errors are you getting? – Anne Gunn Dec 22 '16 at 19:17
  • I don't know how to start! Pls do help out :) – kaysri Dec 22 '16 at 19:26
  • There aren't any Python implementations that I know of. However, there are many implementations in other languages in the duplicate link I've posted which can be very easily transcribed to Python. One algorithm that I've used successfully is the Felzenszwalb and Huttenlocher algorithm that is linear time complexity (`O(N)`). – rayryeng Dec 23 '16 at 06:32

0 Answers0