implementation of distance transform of given binary image

277 views Asked by At

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

0

There are 0 answers