tags:

views:

349

answers:

1

i am trying to extract outline path from given bitmap, i create a fast algorithm (for me) on as3 and that is:

    //@v source bitmap's vector data
    //@x x to starting extraction
    //@y y to stating extraction
    //@w extraction width
    //@h extraction height
    //@mw source bitmap width
    //@mh source bitmap height
    private function extractRects(v:Vector.<uint>, x:int, y:int, 
                                w:int, h:int, mw:int, mh:int):Array
    {
        var ary:Array = [], yy:int=y, vStart:int, _xx:int, xx:int;
        var lcold:int = 0, lc:int;
        //first line to last line
        while(yy < h)
        {
         //first index of current vector
         vStart = yy * mw + x;
         xx = x;
         lc = 0;
         //first vector to last on current scan
         while(xx < w)
         {
          /*
           if current vector value (color) is 
           empty (transparent) then
           check next
          */
          while(xx < w && !v[vStart])
          {
           vStart++;
           xx++;
          }
          //it is not empty so copy first index
          _xx = xx;
          //check till value is not empty
          while(xx < w && v[vStart])
          {
           xx++;
           vStart++;
          }
          //create rectangle
          var rr:Rectangle = new Rectangle(_xx, yy, (xx-_xx), 1);
          //if previous line has the same rectangle index
          if(lc < lcold)
          {
           var oldrr:Rectangle = ary[ary.length - lcold];
           //if previous neighbour rect on top
           //has same horizontal position then
           //resize its height
           if(oldrr.left == rr.left && oldrr.width == rr.width)
            oldrr.height++;
           else
            ary.push(rr);
          }
          else
           ary.push(rr); 
          lc++;
          xx++;
         }
         lcold = lc;
         yy++;
        }
        return ary;
    }

by the method above, i extract the region and create shape by drawing rects.. drawing rects not a good solution for me because of non-smooth view.

to have smoother view, i should use lines or curves but, calculation of point neighbouring is really big headache for me with sleepy eyes right now.

could you recommend me some well-known or any better solution?

as3, c++, c#, vb.net, vb6, delphi, java or similar languages will be fine for answers.

thanks your advance..

EDIT FOR CLEARIFICATION

I am trying to extracting non-transparent pixels' x, y coordinates from a bitmap to drawing on different path data. (32 bit ARGB) (creating shape)

to drawing i could use lineTo, curveTo, moveTo operations

moveTo(x, y)
lineTo(x, y)
curveTo(cx, cy, ax, ay)

in my code, i thought that i could extract the rectangles of current non-transparent blocks and i could use the same rects with moveTo and lineTo operations on further graphic methods

the problem is using this method gives non-smooth look on edges which is neighter horizontal nor vertical

so, the solution is creation a point map on edges, detecting the point neighborhood, using the lineTo operation (because it generates antialiased lines) between neighbour points on rows, or calculating the points placement on nearest circle area and using curveTo method..

my question is could you recommend me some algorithms or methods for extracting job.

sorry for my English

thank you

A: 

What you're looking for is bitmap/raster image to vector software. To get a good quality result, there are many non-trivial steps that must be performed. There is an open source project called Potrace which does this - click here for a technical description of how it works. If you'd like to try its algorithm in an GUI program, you can use Inkscape with its Trace Bitmap function.

James Kolpack