따라서 입력 각도가 theta
이고 좌표가 points
이라면 그 각도에서 최소 둘러싸는 직사각형을 원하십니까? (그 의미는 무엇입니까? - 높이 축이 해당 각도에서 너비 축으로 설정되고 각도 수직 방향 (표제와 같은) 또는 수평 - 시계 반대 방향 (수학과 같은)에서? 더 자세히 말하자면, 너비가> 너비가되도록 높이를 조정합니다. 이 경우
, 나는 다음과 같은 작업 것 같아요 :
- 각도
theta
회전 단지 XY 축으로하는 새로운 좌표계로 좌표를 변환
- (이것에 대한 회전 행렬을 사용) 이 좌표계에서 최소 둘러싸는 직사각형을 찾으십시오 : 이제는 수평 - 수직 차원에서 최소 둘러싸는 직사각형을 찾습니다 (좌표가 이미 변환되었으므로 더 이상
theta
을 걱정할 필요가 없습니다)
- 최소한의 외장 사각형 h 높이> = 너비로
- 직사각형을 다시 원래 좌표계로 변환합니다 (다시
theta
로 회전).
- 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))
아, 죄송 합니다만, stddev/mean을 계산하는 것을 잊어 버렸습니다. 업데이트 된 답변 : P –