Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, let me explain what an "edge" is.</p> <p>An edge is the virtual line between two contiguous pixels.</p> <pre><code>+---+---+ | A | B | // The middle line is the edge between pixel A and pixel B +---+---+ </code></pre> <p>Edges have a starting point and an end point, and so are oriented upward, downward, "left going" or "right going".</p> <p>In order to handle polygons crossing image boundaries, we gonna add a 1 pixel white border around our image.</p> <p>Here is the algorithm:</p> <pre><code>For each row of our image { For each pixel of the row except the last one { If current pixel is white and next pixel is black { Create a new upward edge between the two pixels and add it to the global edge list. } Else if current pixel is black and next pixel is white { Create a new downward edge between the two pixels and add it to the global edge list. } } } For each column of our image { For each pixel of the column except the last one { If current pixel is white and next pixel is black { Create a new "left going" edge between the two pixels and add it to the global edge list. } Else if current pixel is black and next pixel is white { Create a new "right going" edge between the two pixels and add it to the global edge list. } } } For each edge of the global edge list { Find the edge starting from the point where your current edge ends (for now on, we gonna call it next_edge). Connect the two edges to form a linked list (edge-&gt;next = next_edge; next_edge-&gt;previous = edge;) } While there is edges in the global edge list { Create a new polygon and add it to the polygon list Take the first edge of the list (for now on, we gonna call it first_edge) For each edge in the linked list starting at first_edge { Remove edge from global edge list Add edge to polygon's edge list } } </code></pre> <p>Done, you have a list of polygons.</p> <p><strong>EDIT</strong></p> <p>Of course, you have to optimize it a little before using it, but it's really easy : consecutive edges with the same orientation can be replaced with a single, longer edge.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload