MATLAB Answers

rotation matrix and regionprops

2 views (last 30 days)
michael scheinfeild
michael scheinfeild on 1 Oct 2014
Commented: Image Analyst on 1 Oct 2014
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 Comment
michael scheinfeild
michael scheinfeild on 1 Oct 2014
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

Sign in to comment.

Answers (1)

Matt J
Matt J on 1 Oct 2014
Edited: Matt J on 1 Oct 2014
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 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!