good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Well, it's too late/early today for any code (sorry), perhaps tomorrow if it won't look too stupid in the morning, and it appears like roboticus knows much better, but I started with this answer before his, so FWIW: 0. Slightly modify your algorithm to eliminate corner points (see below why). 1. Starting with original image, triple it, i.e. each pixel (point). 2. Apply your algorithm. Original fragment: # # # # . # # # . . # # . . . # # # # . # # . . . After your algorithm: # # # # . o o # . . o # . . . o o # # . # # . . . Original was tripled, algorithm applied (corners eliminated), ###########. ...........# .........##. ..# ..# .##. ..# ..# ..# ......#####. ...........# ......#####. ..# ..# #####. So, now every marked pixel is guaranteed to have only 2 neighbours. 4. Then it's trivial to start anywhere and just pick unused neighbour until polyline closed. 5. Scale polyline to original (integer division?). 6. Reduce it to eliminate same points as begin-end. In reply to Re: Polygon Creation -- Request for Algorithm Suggestions
by vr
|
|