2011-12-30 5 views
0

인사말 오버플로,평균 및 표준 편차 계산

저는 MatLab에 회색 이미지 행렬이 있고 그 이미지의 특정 픽셀 좌표가 거의 없습니다. 이 각도 위치

  1. (예를 들어 0, 45, 90, 135)
  2. 가 모두 포함 같은 그 I는 행렬의 사각형 영역 내의 값의 평균과 표준 편차를 산출 할 몇 픽셀
  3. 면적 내가 수직, 수평 및 두 대각선 경우에 그렇게 할 수 있을지는 것하지만 내가 행복 할 것입니다 지금은 각 각에 대한 최소 높이> = 폭

입니다 내가 어떤 각도로도 그것을 할 수 있다면 정말 고마워.

아이디어가 있으십니까?

답변

3

따라서 입력 각도가 theta이고 좌표가 points이라면 그 각도에서 최소 둘러싸는 직사각형을 원하십니까? (그 의미는 무엇입니까? - 높이 축이 해당 각도에서 너비 축으로 설정되고 각도 수직 방향 (표제와 같은) 또는 수평 - 시계 반대 방향 (수학과 같은)에서? 더 자세히 말하자면, 너비가> 너비가되도록 높이를 조정합니다. 이 경우

, 나는 다음과 같은 작업 것 같아요 :

  1. 각도 theta 회전 단지 XY 축으로하는 새로운 좌표계로 좌표를 변환
  2. (이것에 대한 회전 행렬을 사용) 이 좌표계에서 최소 둘러싸는 직사각형을 찾으십시오 : 이제는 수평 - 수직 차원에서 최소 둘러싸는 직사각형을 찾습니다 (좌표가 이미 변환되었으므로 더 이상 theta을 걱정할 필요가 없습니다)
  3. 최소한의 외장 사각형 h 높이> = 너비로
  4. 직사각형을 다시 원래 좌표계로 변환합니다 (다시 theta로 회전).
  5. mean/stddev를 계산하려면이 좌표를 사용하십시오. 이 (안된) 일할 수있는 것처럼

뭔가 당신의 욕망을 조정할 : 다음

% 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(:)]'; 

과 같이 사용합니다 (하나주의해야 할 점은 내가 대 X/Y 인/J) :

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

아, 죄송 합니다만, stddev/mean을 계산하는 것을 잊어 버렸습니다. 업데이트 된 답변 : P –