- 追加された行はこの色です。
- 削除された行はこの色です。
* octave で画像処理 - 画像の縮小 bilinear 法 [#kfe225b2]
アンチエイリアジングフィルタとして bilinear 法を使って画像を縮小してみます.
フィルタが bilinear 法に変わっただけで,考え方や手順は[[前回>日記/2010-04-24/octave で画像処理 - 画像の縮小 nearest neighbor 法]]と一緒です.
** bilinear フィルタの重み付け係数 [#kf5a34f1]
係数の比率としては[[画像の拡大>日記/2010-04-13/octave で画像処理 - bilinear 法]]と全く一緒です.
が,今回は黒画素が水増しされてるわけではないので,係数の総和が 1 になるよう正規化します.
|1/16|1/8|1/16|
|1/8|1/4|1/8|
|1/16|1/8|1/16|
** フィルタリング [#q600c10e]
それでは octave 上で実際にやってみます.
octave:1> [ x m a ] = imread ( 'gaishi.jpg' );
octave:2> x = double ( x ) / 255;
octave:3> h = [ .25 .5 .25; .5 1 .5; .25 .5 .25 ]/4;
octave:4> xf(:,:,1) = conv2 ( x(:,:,1), h );
octave:5> xf(:,:,2) = conv2 ( x(:,:,2), h );
octave:1> [ x m a ] = imread ( 'gaishi.jpg' ); # 元画像の読み込み
octave:2> x = double ( x ) / 255; # double 型に変換
octave:3> h = [ .25 .5 .25; .5 1 .5; .25 .5 .25 ]/4; # 重み付け係数の定義
octave:4> xf(:,:,1) = conv2 ( x(:,:,1), h ); # RGB 各プレーンに対して
octave:5> xf(:,:,2) = conv2 ( x(:,:,2), h ); # フィルタを適用
octave:6> xf(:,:,3) = conv2 ( x(:,:,3), h );
octave:7> imshow ( xf );
octave:7> imshow ( xf ); # 画像のプレビュー
#ref(gaishi_bl.jpg,center)
octave:8> x2 = resample( xf, 2 );
octave:9> imshow ( x2 );
octave:10> imwrite ( xf, 'gaishi_bl.jpg', 'jpg' );
octave:11> imwrite ( x2, 'gaishih_bl.jpg', 'jpg' );
** 画素の間引き [#u35f2a85]
octave:8> x2 = resample( xf, 2 ); # 画素の間引き
octave:9> imshow ( x2 ); # 画像のプレビュー
#ref(gaishih_bl.jpg,center)