0

オーバーフローの皆さん、こんにちは。

MatLab に灰色の画像マトリックスがあり、その画像の特定のピクセル座標はほとんどありません。そのマトリックスの長方形の領域内の値の平均と標準偏差を次のように計算したいと思います。

  1. 角度を付けて配置されている (例: 0、45、90、135)
  2. いくつかのピクセルがすべて含まれています
  3. その面積は各角度で最小であり、その高さ >= 幅

今のところ、縦、横、対角の両方の場合にそうしていただけると嬉しいのですが、手持ちのどの角度でもできるようになれば本当にありがたいです。

何か案は ?

4

1 に答える 1

3

したがって、入力 anglethetaと座標の束が与えられると、pointsその角度で最小の囲み長方形が必要になります (それはどういう意味ですか? -- 高さ軸はその角度に設定されていますか? 幅軸? そして、垂直時計回りからの角度 (のように)見出し) または水平-反時計回り (数学のように)?)。さらに、幅 >= になるように高さを調整します。

その場合、次の方法が有効だと思います。

  1. 座標を、xy 軸を角度だけ回転させた新しい座標系に変換しますtheta(これには回転行列を使用します)。
  2. thetaこの座標系で最小の囲み長方形を見つけます: これは、水平垂直方向の寸法で最小の囲み長方形を見つけるだけです (したがって、座標は既に変換されているので、これ以上心配する必要はありません)。
  3. 最小の囲み長方形が高さ >= 幅であることを確認してください
  4. 四角形を元の座標系に変換します ( で回転させますtheta)。
  5. これらの座標を使用して、平均/標準偏差を計算します。

このようなものは機能する可能性があります(テストされていません)。必要に応じて微調整してください:

% 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) )
于 2011-12-30T11:15:05.157 に答える