Matlab imregionalmax / imregionalmin関数C ++の実装



Matlab Imregionalmax Imregionalmin Function C Implementation



matlabプログラムをC ++バージョンに変更する場合、imregionalmaxとimregionalminを使用して、行列の行と列の極値を解決しました。

形式:imregionalmax(A、n)
注:Aは2Dデータまたは3Dデータを使用できます。nは極値を見つけるために使用される方法です。デフォルトは2D n = 8(8隣接法)3D n = 26.2 Dの場合、n = 4/8(3Dの場合)、n = 6/18/26。
戻り値:Aと同じ構造のバイナリ論理行列(1:極大値を意味します0は非極大値を意味します)。



matlabでの実行結果は上記のとおりです。
詳細な内容については、以下を参照してください。 Matlabの1次元離散データの極値と極値の位置の計算

実験で必要なのは、一連の画像データを解くことです。変換されたC ++コードは次のとおりですint FindFirstDiffNum(const vector &num, vector &peakValley, unsigned startPos, int flag) { if (flag> 0) //Find the position of the next rightmost crest such as: 1 2 3 4 4 4 3 2 The position of the last crest is 5, and the third 4 { for (unsigned i = startPos i startPos j--) // can be changed to only take both ends { if (num[j] == num[i]) peakValley[j] = -1 else break } return i } else { continue } } return 0 } } // possible extreme points in the data // num: the input array, only a row/col // peakValley: the output array, only contents 0,1 1---peaks, 0---valley void findPeaks(const vector &num, vector &peakValley) { unsigned count = 0 int dif = 0 int ret = 0 while (count 0) count = ret else break } } } int main(int argc, char* argv[]) { int arr[] = { 15, 18, 19, 145, 168, 255, 255, 255, 234, 168, 11, 11, 15, 11, 11, 84, 84, 26, 57, 88 } vector data vector peakValley(20, 0) for (int i = 0 i




結果の表示:





比較結果:matlabには、実際のニーズに応じて調整できるヘッドとテールが含まれています。