rotation matrix and regionprops

2 次查看(过去 30 天)
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
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

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by