昨日に引き続き画像処理手法の簡単な紹介。
このフィルタは画素値を周りに拡散させます。
Photoshopの [フィルタ] > [表現技法] > [拡散]と同じ効果です。
実際の処理は参照する座標値をランダムに決めているだけ。
・ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
package { import __AS3__.vec.Vector; import flash.display.*; [SWF(width = "600", height = "250", backgroundColor = "#000000", frameRate = "30")] public class Jitter extends Sprite{ [Embed(source = 'assets/picture.jpg')] public var SrcImg:Class; private var src:Bitmap; private var dst:Bitmap; private var srcData:Vector.<uint>; private var w:int; private var h:int; public function Jitter() { stage.scaleMode = "noScale"; src = new SrcImg() as Bitmap; w = src.width; h = src.height; dst = new Bitmap(new BitmapData(w, h, false)); addChild(src); srcData = new Vector.<uint>(w*h, true); srcData = src.bitmapData.getVector(src.bitmapData.rect); dst.bitmapData.setVector(dst.bitmapData.rect, filterJitter(srcData, 10)); addChild(dst).x += w; } private function filterJitter(src:Vector.<uint>, amount:int):Vector.<uint> { var dst:Vector.<uint> = new Vector.<uint>(w*h, true); var nx:int, ny:int; for (var y:int=0;y<h;y++) { for (var x:int=0;x<w;x++) { nx = x + (Math.random() - 0.5)*amount; ny = y + (Math.random() - 0.5)*amount; try { dst[w*y + x] = src[w*ny + nx]; }catch(e:RangeError) { dst[w*y + x] = src[w*y + x]; }catch(e:ReferenceError) { dst[w*y + x] = src[w*y + x]; } } } return dst; } } } |
・関連記事
Symmetric Nearest Neighbour
I like this filter,thank you :)