1

ここでのプログラミングは初めてで、これにアプローチする方法が本当にわかりません。

私の問題:長方形の境界ボックスで注釈が付けられた画像がたくさんあり、既存の境界ボックスと重複しない他の長方形の境界ボックスをランダムに選択したい。したがって、基本的に、行列 M と M の部分行列の事前定義されたサブセット X があり、X と重複しないが互いに重複できるランダムな位置を持つ新しい部分行列を生成したいと考えています。生成された部分行列は、X の部分行列とほぼ同じサイズで、行列 M に含まれている必要があります。

ここに画像の説明を入力

http://i.imgur.com/74AEI2x.png

上の例では、その画像のボックスは X、つまりサッカー ボールの正の例を表しています。サッカー ボールの負の例を表すために、サッカー ボールを囲んでいない同じサイズのボックスを同数生成したいと考えています。

どんな方向でも大歓迎です。私はこれを MATLAB で行っています。

4

2 に答える 2

1

コードとコメントを見て、質問で設定された目標をどのように達成できるかを理解してみましょう。

%// Bounding box array, where the first and second columns denote the X-Y 
%// location of the uppper-left corner pixel. The third and fourth columns
%// denote the extent of the repctive boxes along X and Y directions 
%// respectively. Some random values are used here for demo purposes.
bb = [
    12 10 10 5
    15 20 14 12
    135 60 11 4
    20 30 10 7
    20 30 13 13
    20 30 13 14]

%// Tolerance in terms of the size difference betwen similar boxes that
%// is admissible as a less than or equal to value
tol = 2

%// Get X and Y direction limits for each box
xlims = [bb(:,1) bb(:,1) + bb(:,3)]
ylims = [bb(:,2) bb(:,2) + bb(:,4)];

%// Create a binary matrix that decides whether each box is in or out with
%// respect to all other boxes along both X and Y directions. Ones mean "in"
%// and zeros denote "out".
x1 = bsxfun(@ge,xlims(:,1),xlims(:,1)') & bsxfun(@le,xlims(:,1),xlims(:,2)')
x2 = bsxfun(@ge,xlims(:,2),xlims(:,1)') & bsxfun(@le,xlims(:,2),xlims(:,2)')
x12 = x1 | x2;

y1 = bsxfun(@ge,ylims(:,1),ylims(:,1)') & bsxfun(@le,ylims(:,1),ylims(:,2)')
y2 = bsxfun(@ge,ylims(:,2),ylims(:,1)') & bsxfun(@le,ylims(:,2),ylims(:,2)')
y12 = y1 | y2;

d1 = x12 & y12

%// Create another binary matrix based on sizes to decide for each box
%// what other boxes are "similar"
szmat = bb(:,[3 4])
v1 = abs(bsxfun(@minus,szmat,permute(szmat,[3 2 1])));
szmat_d = squeeze(all(v1<=tol,2));

%// Get a binary matrix based on combined decisions from X-Y incompatibility
%// and sizes. Please note for incompatibility, negation of d1 is needed.
out1 = ~d1 & szmat_d
out1(1:size(out1,1)+1:end)=0
out2 = mat2cell(out1,ones(1,size(out1,1)),size(out1,2))
out3 = cellfun(@find,out2,'uni',0)

コードの使い方 -

out3は、各ボックスの最終決定を格納する最終出力であり、他のどのボックスが類似しており、重複していません。検証のために、次のようにして、ボックス 1 のこれらの基準に適合する他のボックスを見てみましょうout3{1}3これはとを出力し4ます。つまり、ボックス 3 と 4 はボックス 1 のボックスです。これは、バウンディング ボックス配列 の値を調べることで手動で確認できますbb

于 2014-05-22T20:18:19.960 に答える