matlab padarray(A、padsize、 'symmetric')関数を使用して実装されたOpenCVは、単純に実現されました



Opencv Implemented Using Matlab Padarray



  • Matlabドキュメントpadarrayメソッドの説明:
    B = padarray(A、padsize、padval)pads配列Aここで、padvalは、パッド値として使用する値を指定します。 padarrayは、デフォルトとして値0(ゼロ)を使用します。 padvalは、パッド値を直接指定するスカラー、またはpadarrayがパディングとして追加された要素の値を決定するために使用するメソッドを指定する次のテキスト文字列のいずれかです。
意味
「円形」 次元内の要素の円形の繰り返しでパッドします。
「複製」 配列の境界要素を繰り返して埋めます。
「対称」 それ自体のミラー反射を備えたパッドアレイ。

例1
ベクトルの先頭にパディングの3つの要素を追加します。灰色の網掛けで示されているパディング要素には、配列要素のミラーコピーが含まれています。
ベクトルの先頭に3つのパディング要素を追加します。パディング要素は、ミラーコピーを構成する配列要素の灰色の陰影で示されます。

a = [ 1 2 3 4 ] b = padarray(a,[0 3],'symmetric','pre')

結果:



b == 3 2 1 1 2 3 4 % Before the three numbers 321 to fill the element
  • OpenCVは、(A、padsize、 'symmetric')関数のpadarraymatlabを実現します。
    C ++コード関数で
//Replicate the boundaries of the InImage image // copy the boundary of the input image //symmetric:Pad array with mirror reflections of itself. Mat PadArray(Mat Image, int RowPad, int ColPad) { int n = Image.rows int m = Image.cols Mat temp1 = Mat::zeros(n, m + ColPad * 2, Image.type()) Mat temp2 = Mat::zeros(n + RowPad * 2, m + ColPad * 2, Image.type()) for (int i = 0 i 1 - i)) Image.col(m - 1 - i).copyTo(temp1.col(m + ColPad + i)) } Image.copyTo(temp1.colRange(ColPad, m + ColPad)) for (int j = 0 j 1 - j)) temp1.row(n - 1 - j).copyTo(temp2.row(n + RowPad + j)) } temp1.copyTo(temp2.rowRange(RowPad, n + RowPad)) return temp2 }

主な機能:

int main() { Mat C = (Mat_<double>(3, 3) << 1, 2, 3, 4, 5, 6789) cout << C << endl << endl << endl Mat B = PadArray(C, 1, 2) cout << B << endl return 0 }

演算結果:



Results are mirrored packed around the original matrix

padarray

  • その他の指示:
    他のオーバーロードpadarrayアップロードプロセスの機能の後、これは単純な実装です。