Automatic vectorization of a binary mask raster?

Hi,

is there a way how to accomplish an automatic vectorization of polygons defined by a two colors raster? That means it only contains white and black color and what I would like to vectorize are the polygons defined by the image borders and the transitional plain between the two colours - for better illustration I've attached examples of the input and desired output...

 The only workaround I have found so far, is to call first an enhanced image filter for detecting edges, which detect me the boundary line of pixels and then to utilize "vectorize area" function which (with a proper setting of the line width) detect me this line...  But that is only the line, I would need a complete area :(

 I also need to automate this process as much as possible (so the VBA based solution, if exists, would be even more welcomed).

 Do you have any hints how to achieve this?

 

Jiri Novak,

CUZK

  • Hi Jiri,

    From the top of my head here is the rough description of one algorithm which might give good result:

    1- Select a white pixel in the image which is not in the already visited pixel buffer.

    2- Put the coordinate of this white pixel in an already visited pixel buffer.

    3- If one of the 8 pixels around the white pixel is black.

    4-    Store this pixel in the current polygon point buffer.

    5- If none of the 8 pixels not already visited around the current white pixel is white.

    6-    create a polygon from the points stored in the polygon point buffer.

    7-    Go to step 1.

    8- Otherwise

    9-    Select one of the 8 pixels around the current white pixel that

          is white and has not already been visited.

    10- Go to step 2.

    The algorithm finish when there is no white pixel in the image that can be selected in step 1 because there is no white pixel in the images or they have been already all visited.

    HTH,

    Mathieu