rotation matrix and regionprops

1 回表示 (過去 30 日間)
michael scheinfeild
michael scheinfeild 2014 年 10 月 1 日
コメント済み: Image Analyst 2014 年 10 月 1 日
hello i have some binary image i found the orientation and rotated the image
stats1 = regionprops(bw,'Orientation','Area');
bwRot=imrotate(bw,-stats1.Orientation);
after finding some interesting pixels i want to find their locations in the original image i create the matrix and try to rotate back but recive negative coordinates any help ,,
stats2 = regionprops(bwRot,'BoundingBox');
bx = stats2.BoundingBox;
xy = [ bx(1:2) ;
bx(1)+bx(3) ,bx(2);
bx(1)+bx(3) ,bx(2)+bx(4);
bx(1) ,bx(2)+bx(4);];
ct = cosd(stats1.Orientation);
st = sind(stats1.Orientation);
% rotation matrix
MatrxRotInv = [ct -st 0 ;
st ct 0;
0 0 1];
xyz = MatrxRotInv* [xy ones(4,1)]' ;
here the xy is negative why ?
  1 件のコメント
michael scheinfeild
michael scheinfeild 2014 年 10 月 1 日
also somthing strange i have image 640*480 newimage=imrotate(image,60) oldimage=imrotate(newimage,-60)
the oldimage size is not the same as image

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2014 年 10 月 1 日
編集済み: Matt J 2014 年 10 月 1 日
You need to call imrotate with the 'crop' option to preserve the size of the input image.
As for the negative xy, it is possible for a rotation to bring points in/out of the image field of view. That's the whole reason why imrotate has the 'crop' option to begin with.
Be mindful as well that imrotate's origin of rotation is at the center of the image. However, the BoundingBox coordinates are relative to an origin at the upper left corner of the image.
  2 件のコメント
Matt J
Matt J 2014 年 10 月 1 日
michael scheinfeild Commented:
ok great !!! now after i found the bound box of the rotated shape how i can warp it back to normal rectange
Image Analyst
Image Analyst 2014 年 10 月 1 日

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by