Rotating points around a center point

조회 수: 1 (최근 30일)
Olivia Foley
Olivia Foley 2017년 3월 22일
편집: Matt J 2017년 3월 22일
Hello. I am currently writing a plugin for a custom program written by my professor. I have an image of a participant and I have a plugin already that allows me to pin point two points on their face. I can rotate the image and I want the points to rotate with the image. This is what I have:
function varargout = rotateClockwise(plusMinus);
%
% By Olivia Foley
% February 28, 2017
WASLx = gcbf;
UserData = WASLx.UserData;
frame = str2num(UserData.plugin.OFP.videoFrameNumber.String);
UserData.plugin.OFP.rotationAngle(frame) = UserData.plugin.OFP.rotationAngle(frame) + str2num(UserData.plugin.OFP.VideoRotateValue.String);
UserData.plugin.OFP.videoImage.CData = imrotate(UserData.plugin.OFP.videoFrames{frame},UserData.plugin.OFP.rotationAngle(frame));
% Moving the dots
t = [UserData.plugin.OFP.transducerDot{frame}.XData, UserData.plugin.OFP.transducerDot{frame}.YData];
n = [UserData.plugin.OFP.noseDot{frame}.XData, UserData.plugin.OFP.noseDot{frame}.YData];
alpha = UserData.plugin.OFP.rotationAngle(frame);
Rx = [cosd(alpha) -sind(alpha);sind(alpha) cosd(alpha)];
centerX = (size(UserData.plugin.OFP.videoImage.CData,2))/2;
centerY = (size(UserData.plugin.OFP.videoImage.CData,1))/2;
% plot(centerX,centerY,'k+');
Ry1 = [t(1)+centerX, t(2)+centerY];
Ry2 = [n(1)+centerX, n(2)+centerY];
% plot(t(1)+centerX, t(2)+centerY,'b*');
% plot(n(1)+centerX, n(2)+centerY,'g*');
Rxy1 = Ry1*Rx;
Rxy2 = Ry2*Rx;
% plot([Rxy1],'bo');
% plot([Rxy2],'go');
UserData.plugin.OFP.transducerDot{frame}.XData = Rxy1(1)-centerX;
UserData.plugin.OFP.transducerDot{frame}.YData = Rxy1(2)-centerY;
UserData.plugin.OFP.noseDot{frame}.XData = Rxy2(1)-centerX;
UserData.plugin.OFP.noseDot{frame}.YData = Rxy2(2)-centerY;
% Rotate and translate the data
%UserData.plugin.OFP.rotationAngle(frame) = (UserData.plugin.OFP.rotationAngle(frame)-repmat(mean(UserData.plugin.OFP.rotationAngle(frame)),size(UserData.plugin.OFP.rotationAngle(frame),1),1))*Rxy + ...
% repmat(mean(UserData.plugin.OFP.rotationAngle(frame)),size(UserData.plugin.OFP.rotationAngle(frame),1),1) + ...
% ones(size(UserData.plugin.OFP.rotationAngle(frame))); %* ...
% diag([leftRight, ...
% upDown, ...
% frontBack]);
% t_center = t(1);
% n_center = n(1);
%
% Rz = repmat([t_center; n_center], 1, length(t));
%
% s = Ry - Rz;
%
% so = Rx*s;
%
% vo = so + Rz;
%
% % Rxy = Rx*Ry;
%
% T_rotated = vo(1,:);
% N_rotated = vo(2,:);
%
% plot(T_rotated, N_rotated,'r+');
% linkdata off;
% % Rotate and translate the data
% UserData.plugin.OFP.trackingDot = (UserData.palate(n).data-repmat(mean(UserData.palate(n).data),size(UserData.palate(n).data,1),1))*Rxy + ...
% repmat(mean(UserData.palate(n).data),size(UserData.palate(n).data,1),1) + ...
% ones(size(UserData.palate(n).data)) * ...
% diag([leftRight, ...
% upDown, ...
% frontBack]);
% fcn2 = @plugins.OFP.updatePosition;
% addNewPositionCallback(UserData.plugin.OFP.setVideoRotationValue,fcn2);
% if ~strcmp(UserData.plugin.OFP.rotateClockwise.String,'Accept'),
% UserData.plugin.OFP.rotateClockwise.String = 'Accept';
%
% % x = mean(UserData.plugin.OFP.videoOverlay.XData);
% % y = mean(UserData.plugin.OFP.videoOverlay.YData);
% %
% % xlims = get(UserData.plugin.OFP.display,'XLim');
% % ylims = get(UserData.plugin.OFP.display,'YLim');
% % fcn = makeConstrainToRectFcn('impoint',[xlims(1)*1.001 xlims(2)*0.999],[ylims(1)*1.001 ylims(2)*0.999]);
% % UserData.plugin.OFP.impoint = impoint(UserData.plugin.OFP.display,x,y);
% % api = iptgetapi(UserData.plugin.OFP.impoint);
% % api.setDragConstraintFcn(fcn);
% % setColor(UserData.plugin.OFP.impoint,'k');
%
% % Start imdistline
% else,
% UserData.plugin.OFP.rotateClockwise.String = 'Clockwise';
% delete(UserData.plugin.OFP.impoint);
% % Get rid of imdistline
% end;
WASLx.UserData = [];
WASLx.UserData = UserData;
I'm not getting any errors, but the dots are not in the right place. I cannot figure out how to get the dots to rotate correctly--they are too low.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by