2009-12-29 72 views
2

我目前正在使用Flex編寫圖像編輯應用程序,並且正在嘗試製作像picnik.com中的瑕疵刪除功能。刪除數字圖像中的瑕疵

我到處搜索,但找不到任何東西。 什麼是適合這個最好的方法?

我試圖只模糊了瑕疵,但結果很糟糕。

+0

爲什麼結果不好?你能詳細說明你做了什麼嗎? – Andres 2009-12-29 01:34:07

+0

模糊它們之後,我得到了模糊的矩形或圓形形狀。並且模糊的部分顏色較深,然後其周圍.. – 2009-12-29 01:40:18

+0

我發現了該技術的專利:http://www.patentstorm.us/patents/7277595/claims.html 您可能想要小心以避免此方法或支付版稅。 – Andres 2009-12-29 02:09:06

回答

2

你沒有得到任何其他答案,所以我會試一試。我不知道柔性什麼,但是這可能應該是可行的:

1)用戶選擇的區域(爲了便於討論它是一個圓)

2)您平均邊緣的顏色值的圈子和存儲該顏色。

3)在圖像和周邊的計算平均顏色之間進行高斯混合。也就是說,融合圓的中心比邊緣更多。當你接近邊緣時,混合的量應該消失。這應該可以防止你的圖像上出現模糊的圓形狀。這也有助於防止變暗,因爲瑕疵色不會成爲平均過程的一部分。

祝你好運!

編輯

這裏是一個融合操作一些psudocode。

for (each pixel) 
{ 
    blendingConstant = [A number between zero and one which is close 
    to 1.0 near the edge of the circle, and approaches a threshold 
    value the closer you get to the center]; 

    pixelColor = (blendingConstant * pixelColor + (1.0 - blendingConstant ) * averagePerimiterColor); 
} 

閾值可以是零,也可以不是。你將不得不一直玩,直到它看起來不錯。

+0

嗯,我已經看到了周邊的顏色,但我不知道如何進行混合。是否有一些算法或僞代碼? – 2009-12-30 03:01:50

+0

看我的編輯。希望有幫助。讓我知道你是否需要更多細節,或者它是否無效。 – Andres 2009-12-30 18:11:25

1
function removeblemish(e:MouseEvent):void 

{

var radius = 16; 

var mX:Number = e.localX; 
var mY:Number = e.localY; 

var ar = 0, ag = 0, ab = 0; 
var cnt = 0; 

for(var i:int = 0; i < 360; i++) 
{ 
    var radians:Number = i * Math.PI/180.0; 

    var posX:Number = Math.floor(radius * Math.cos(radians)) + mX; 
    var posY:Number = Math.floor(radius * Math.sin(radians)) + mY; 

    if(posX >= 0 && posX < newBitmap.width && posY >= 0 && posY < newBitmap.height) 
    { 
     var pixel:uint = newBitmap.getPixel32(posX, posY); 
     ar += (pixel >> 16) & 0xFF; 
     ag += (pixel >> 8) & 0xFF; 
     ab += (pixel >> 0) & 0xFF; 
     cnt++ 
    } 
} 

ar = Math.floor(ar/cnt) % 255; 
ag = Math.floor(ag/cnt) % 255; 
ab = Math.floor(ab/cnt) % 255; 

var threshold:Number = 0.75; 

for(var i:int = 0; i <= radius; i++) 
{ 
    for(var j:int = 0; j < 360; j++) 
    { 
     var radians:Number = j * Math.PI/180.0; 

     var posX:Number = Math.floor(i * Math.cos(radians)) + mX; 
     var posY:Number = Math.floor(i * Math.sin(radians)) + mY; 

     if(posX >= 0 && posX < newBitmap.width && posY >= 0 && posY < newBitmap.height) 
     { 
      var blend = threshold + (i * 1.0/radius) * (1.0 - threshold); 

      var pixel:uint = newBitmap.getPixel32(posX, posY); 
      var cr = (pixel >> 16) & 0xFF; 
      var cg = (pixel >> 8) & 0xFF; 
      var cb = (pixel >> 0) & 0xFF; 

      cr = Math.floor(blend * cr + (1.0 - blend) * ar) % 255; 
      cg = Math.floor(blend * cg + (1.0 - blend) * ag) % 255; 
      cb = Math.floor(blend * cb + (1.0 - blend) * ab) % 255; 

      newBitmap.setPixel32(posX, posY, (255 << 24) | (cr << 16) | (cg << 8) | cb); 
     } 
    } 
} 

}

這一工程!謝謝! 他是我得到的......但如果半徑變小,仍然有一些暈圈......有沒有辦法改進它?

+0

像素中的圓圈有多小?瑕疵是否與周邊重疊? – Andres 2010-01-04 17:47:16

+0

順便說一句,必須有一個更好的方式來遍歷你的圈子中的像素。你的錯誤可能是由此造成的。在0到360之間不僅浪費週期,而且會擾亂數學。嘗試在(mx + - radius)和(my + - radius)之間迭代。然後做一個測試,看看像素是在圈內還是在周邊,取決於循環。 – Andres 2010-01-04 17:56:24