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;
}
With the above method, I extract the region and create shape by drawing rectangles..
Drawing rectangles does not seem to be a good solution because of non-smooth view.
In order to have a smoother view, I must use lines or curves but, using point neighbouring technique is really big headache for me right now.
Could anyone please recommend me any better solution?
as3, c++, c#, vb.net, vb6, delphi, java or similar languages will be fine for answers.
EDIT FOR CLEARIFICATION
I am trying to extract non-transparent pixels’ x, y coordinates from a bitmap to draw on different path data. (32 bit ARGB) (creating shape)
For 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 rectangles with moveTo and lineTo operations on further graphic methods
The problem is that this method gives non-smooth look on edges which is neither horizontal nor vertical.
So, the solution is creating 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..
Question Could anyone recommend me some algorithms or methods for extracting job?
Thanks in advance
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.