Image-Py / sknw

build net work from skeleton image (2D-3D)
BSD 3-Clause "New" or "Revised" License
224 stars 48 forks source link

Is it possible to add angled parts to a graph as points? #25

Open ghost opened 2 years ago

ghost commented 2 years ago

Hello. I found this package to make floorplan Binary Image to graph like this. room I make it to skeleton image and result is here. room2 room3 Is it possible to add angled parts where i pointed by arrows to a graph as points?

also ,I wish the graph was composed only of straight lines... is any options?

yxdragon commented 1 year ago

this should be a post process. sknw transform image to vector graph, then you can use some geometry lib (such as shape ly) to simplify the edge.

yxdragon commented 1 year ago

this is a demo generated by chatgpt, It seems ok, but I did not test it

from shapely.geometry import LineString, Point

# Define a line string
line = LineString([(0, 0), (0, 1), (1, 1), (2, 2), (3, 1), (4, 0)])

# Simplify the line string with a tolerance of 0.5
simplified_line = line.simplify(tolerance=0.5, preserve_topology=False)

# Print the original and simplified line strings
print("Original line: ", line)
print("Simplified line: ", simplified_line)