簡體   English   中英

關於:從位圖提取區域

[英]About: Extracting Region From Bitmap

我試圖從給定的位圖提取輪廓路徑,我在as3上創建了一個快速算法(對我來說),那就是:

    //@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;
    }

使用上述方法,我可以提取區域並通過繪制矩形來創建形狀。由於非平滑視圖,繪制矩形似乎不是一個好的解決方案。

為了獲得更平滑的視圖,我必須使用直線或曲線,但是現在使用點相鄰技術確實讓我頭疼。

有人可以推薦我更好的解決方案嗎?

as3,c ++,c#,vb.net,vb6,delphi,java或類似語言都可以作為答案。

編輯澄清

我試圖從位圖中提取非透明像素的x,y坐標以繪制不同的路徑數據。 (32位ARGB)(創建形狀)

對於繪圖,我可以使用lineTo,curveTo,moveTo操作。

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

在我的代碼中,我認為我可以提取當前非透明塊的矩形,並且可以將相同的矩形與moveTo和lineTo操作一起用於其他圖形方法

問題在於該方法使水平或垂直邊緣的外觀都不平滑。

因此,解決方案是在邊緣上創建一個點圖,檢測點的鄰域,使用行上的相鄰點之間的lineTo操作(因為它會生成抗鋸齒的線),或者計算最近的圓形區域上的點的位置並使用curveTo方法。

問題有人可以向我推薦一些提取工作的算法或方法嗎?

提前致謝

您正在尋找的是位圖/光柵圖像到矢量軟件。 為了獲得良好的質量結果,必須執行許多重要的步驟。 有一個名為Potrace的開源項目可以執行此操作- 單擊此處以獲取有關其工作方式的技術說明 如果您想在GUI程序中嘗試其算法,則可以將Inkscape及其Trace Bitmap函數一起使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM