2016-09-24 3 views

답변

0

다음 예제는 회전 된 경계 상자를 자르는 방법을 보여줍니다.

이 예제에서는 테두리 상자를 선택하는 방법과 각도 (사용자 인터페이스 제외)를 표시하지 않습니다.

예제를 단순하게 유지하기 위해 경계 상자 매개 변수는 가운데, 크기 및 각도 (네 모퉁이 대신)입니다.
회전시 중심이 고정됩니다.
크기는 대상 자르기 영역의 너비와 높이 (회전 후의 크기)입니다. https://en.wikipedia.org/wiki/Rotation_matrix

코드 샘플 : 당신이 코너 변환을 계산해야하는 경우

, 당신은 회전 행렬을 사용할 수 있습니다

%Bounding box parameters: center, width, height and angle. 
%Center is selected, because center is kept the same when rotating. 
center_x = 256; %Center column index (applied center is 256.5) 
center_y = 192; %Center row index (applied center is 192.5) 
width = 300; %Number of columns of destination (cropped) area (even integer) 
height = 200; %Number of rows of destination (cropped) area (even integer) 
phi = 120; %Rotation angle in degrees 

%Read sample image. 
I = imread('peppers.png'); 

%Add center cross, for verifying center is kept. 
I(center_y-1:center_y, center_x-30:center_x+30, :) = 255; 
I(center_y-30:center_y+30, center_x-1:center_x, :) = 255; 

%Rotate the entire input image, dimensions of J will be the same as I. 
J = imrotate(I, phi, 'bicubic', 'crop'); 

%Crop rectangular are with size width by height around center_x, center_y from J. 
C = J(center_y-height/2+1:center_y+height/2, center_x-width/2+1:center_x+width/2, :); 

%Display result: 
figure;imshow(C); 

결과 :
enter image description here

+0

정말 감사합니다. 그게 내 문제를 해결해 줬어. – David

관련 문제