We have got image 100×100 pixels. In this image red line is a path. When i parse this image to pixel colors i get red pixel in random order (in fact i get pixels from image line by line from top to bottom). But i want get a list of ordered dots of the path from point A to point B. How to do it.
example of path in image
This function gets pixel with red color (python language):
def getRoad(imgPng) -> list:
img = Image.open(imgPng)
pix = img.load()
width, height = img.size
x = 0
y = 0
road = []
for y in range(BORDER_OFFSET, height-BORDER_OFFSET, STEP):
for x in range(BORDER_OFFSET, width-BORDER_OFFSET, STEP):
color = pix[x, y]
if (COLOR_ROAD[0]-7 <= color[0] <= COLOR_ROAD[0]+7 and
COLOR_ROAD[1]-7 <= color[1] <= COLOR_ROAD[1]+7 and
COLOR_ROAD[2]-7 <= color[2] <= COLOR_ROAD[2]+7):
road.append((x, y))
# print(len(road))
return road