したがって、入力 angletheta
と座標の束が与えられると、points
その角度で最小の囲み長方形が必要になります (それはどういう意味ですか? -- 高さ軸はその角度に設定されていますか? 幅軸? そして、垂直時計回りからの角度 (のように)見出し) または水平-反時計回り (数学のように)?)。さらに、幅 >= になるように高さを調整します。
その場合、次の方法が有効だと思います。
- 座標を、xy 軸を角度だけ回転させた新しい座標系に変換します
theta
(これには回転行列を使用します)。
theta
この座標系で最小の囲み長方形を見つけます: これは、水平垂直方向の寸法で最小の囲み長方形を見つけるだけです (したがって、座標は既に変換されているので、これ以上心配する必要はありません)。
- 最小の囲み長方形が高さ >= 幅であることを確認してください
- 四角形を元の座標系に変換します ( で回転させます
theta
)。
- これらの座標を使用して、平均/標準偏差を計算します。
このようなものは機能する可能性があります(テストされていません)。必要に応じて微調整してください:
% pts is 2xn
% theta is in degrees, anticlockwise from horizontal.
% returns 2xn matrix of indices into the min enclosing rectangle.
function minClosingRect = calcMinEnclosingRect( pts, theta )
% convert to radians and rotate by theta degrees ANTICLOCKWISE
thRad = theta*pi/180;
rotMat = [ cos(thRad) -sin(thRad); sin(thRad) cos(thRad) ];
ptsRot = rotMat * pts;
% find minimum enclosing rectangle of ptsRot
% in the horizontal-vertical direction
% this is just min/max coords.
minX = min(ptsRot(1,:));
maxX = min(ptsRot(1,:));
minY = min(ptsRot(2,:));
maxY = max(ptsRot(2,:));
% make sure height >= width
if (maxY-minY)<(maxX-minX)
% NOTE: depending on how you want you can extend
% - out the bottom
% - the top
% - centred (etc)
% e.g. to make the rectangle taller out the bottom
minY = maxY - (maxX-minX);
end
% construct indices into rectangle
[X Y] = meshgrid( minX:maxX, minY:maxY )
% convert indices back by rotating thRad degrees backwards.
rotMatInv = [ cos(-thRad) -sin(-thRad); sin(-thRad) cos(-thRad) ];
minClosingRect = rotMatInv * [X(:) Y(:)]';
次に、次のように使用します (1 つの注意点は、X/Y 対 i/j です)。
minClosingRect = calcMinEnclosingRect( pts, theta );
mean2( Img(minClosingRect) )
std2( Img(minClosingRect) )