Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

imfilter の境界パディング オプション

イメージの境界の出力ピクセルを計算した場合、畳み込みまたは相関カーネルの一部が、次の図に示すようにイメージからはみ出てしまうのが普通です。

カーネルの値がイメージの外にはみ出る場合

A grid of pixels displaying the pixel values. The 3-by-3 kernel centered on the (1, 4) pixel is highlighted in gray and extends past the edge of the image, where there are no pixels.

関数 imfilter は通常、0 と想定してはみ出たイメージ ピクセルを埋めます。これは通常、ゼロ パディングと呼ばれ、次の図のようになります。

外側ピクセルのゼロ パディング

A grid of pixels displaying the pixel values. Pixels are simulated where the 3-by-3 kernel extends past the edge of the image. The value of the simulated pixels is 0.

イメージをフィルターすると、ゼロ パディングを行った結果、イメージのエッジ周辺が、この例に示すように濃い帯で覆われることがあります。

I = imread("eight.tif");
h = ones(5,5) / 25;
I2 = imfilter(I,h);
imshow(I), title("Original Image");
figure, imshow(I2), title("Filtered Image with Black Border")

On the left is the original image and on the right is the filtered image with dark pixels along the edge of the image.

イメージのエッジ周辺からゼロ パディングのアーティファクトを取り除くため、imfilter には "境界重複" という別の境界パディング方法があります。境界重複では、イメージの外側にあるすべてのピクセルの値が、最寄りの境界ピクセルの値を重複することによって決定されます。これを次の図に示します。

重複された境界ピクセル

A grid of pixels displaying the pixel values. Pixels are simulated where the 3-by-3 kernel extends past the edge of the image. The value of each simulated pixel is equal to the value of the edge pixel adjacent to the simulated pixel.

境界重複を使用してフィルター処理を行うには、追加のオプション引数 "replicate"imfilter に渡します。

I3 = imfilter(I,h,"replicate");
figure, imshow(I3); 
title("Filtered Image with Border Replication")

関数 imfilter は、"circular""symmetric" のような他の境界パディング オプションもサポートしています。

参考

関連するトピック