2011-12-30 16 views
0

グリーティングオーバーフロー、平均と標準偏差を計算する

私は灰色の画像マトリックスをMatLabに持ち、その画像の特定のピクセル座標はほとんどありません。私はそのようなことは、そのマトリックスに矩形領域内の値の平均値と標準偏差を計算する :それは角度(例えば、0、45、90、135)に配置され

  1. それが全て含まれています数ピクセル
  2. 私はでしょうが、私は、縦、横、両方の対角線の例のためにそうすることができれば、今、私は幸せになるためにその面積は、各角度の最小値とその高さ> =その幅

です私はそれを手の中でどんな角度にもできたら本当に感謝しています。

アイデア?

答えて

3

入力角度がthetaで、座標がpointsの場合、その角度には最小の囲み矩形が必要です(これは何を意味しますか?高さ軸はその角度で設定されます。 (見出しのように)または水平に反時計回りに(数学のように)? さらに、幅が>幅になるように高さを調整します。その場合

、Iは、以下がうまくいくかもしれないと思う:

  1. (このための回転行列を使用して)角度thetaによって回転だけXY軸である新しい座標系に座標変換しますこの座標系で最小の囲み矩形を見つけます:これは、水平 - 垂直の次元で最小の囲み矩形を見つけるだけです(既に座標が変換されているため、thetaをもう心配する必要はありません)
  2. 最小の囲み矩形h高さ> =幅として
  3. 矩形を元の座標系に戻します(thetaで元に戻します)。
  4. これらの座標を使用して平均/標準偏差を計算します。

このような何か(未テスト)仕事ができる、あなたの欲求に微調整:

% 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つの警告は、I/J対X/Yである)のようにそれを使用します。

minClosingRect = calcMinEnclosingRect(pts, theta); 
mean2(Img(minClosingRect)) 
std2( Img(minClosingRect)) 
+0

ああ、お詫び申し上げます、私はstddev/meanを計算したいと思います。更新された答え:P –

関連する問題