【问题标题】:Rotating an entire axes in Matlab Guide在 Matlab 指南中旋转整个轴
【发布时间】:2017-02-26 16:31:24
【问题描述】:

我目前正在尝试旋转名为 axes1 的整个轴。

                imr=imrotate(img,30);
                axes(this.gui_h.axes1);
                imshow(imr,'Parent',this.gui_h.axes1);

上面的代码启动了 30 度的旋转。但是,图像会旋转,但不会旋转整个轴 1。我已经测试了诸如 rotate3D 之类的引导工具,但是 rotate3D 不能成功用于 2d 图像。我也试过 set(handles.axes1,'Rotation',-25); ,没有效果。它只是忽略该语句并继续执行其他任务。有没有办法旋转整个轴?

【问题讨论】:

  • 您可以使用:I = imrotate(frame2im(getframe(gca)), 30);,但旋转只是视觉上的(结果是图像,而不是功能轴)。
  • 它似乎只旋转带有轴的图像,而不是轴。除此之外,图像还表示为带有黑色背景的白色正方形
  • 我想旋转整个轴而不只是轴内的图像的原因是,旋转轴不会在图像旋转时改变图像的大小。在轴中旋转图像会改变大小。如果有办法解决这个问题,它也可以是一种选择?

标签: matlab rotation matlab-guide


【解决方案1】:

您可以使用view 函数来旋转轴。

imshow('Jupiter_New_Horizons.jpg')
xlabel('X axis')
ylabel('Y axis')
camzoom(.8)

% Rotate the axes changing the Azimuth value
for i=0:-3:-180
   view([i 90]);
   pause(.3)
end

这也适用于标准地块:

t=0:.1:2*pi;
x=sin(t)
plot(t,x);
grid minor
xlabel('X axis')
ylabel('Y axis')
camzoom(.8)
for i=0:-3:-180
   view([i 90]);
   pause(.3)
end

按照 cmets 进行编辑

我创建了一个简单的 GUI,其中包含两个 axes 和两个 pushbutton 以及以下 tag

  • 轴 #1:轴 1
  • 轴 #2:轴 2
  • 按钮 #1:按钮 1
  • 按钮 #2:按钮 2

pushbutton1callbackaxes1 中加载图像,旋转轴。

pushbutton2callbackaxes2 中绘制一条曲线,旋转轴。

GUI 工作正常,斧头按预期旋转。

这是图形用户界面的.m;您可以创建 GUI 并使用上面指定的 tag 对其进行测试。

function varargout = fbdfi(varargin)
% FBDFI MATLAB code for fbdfi.fig
%      FBDFI, by itself, creates a new FBDFI or raises the existing
%      singleton*.
%
%      H = FBDFI returns the handle to a new FBDFI or the handle to
%      the existing singleton*.
%
%      FBDFI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FBDFI.M with the given input arguments.
%
%      FBDFI('Property','Value',...) creates a new FBDFI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before fbdfi_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to fbdfi_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help fbdfi

% Last Modified by GUIDE v2.5 26-Feb-2017 20:56:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @fbdfi_OpeningFcn, ...
                   'gui_OutputFcn',  @fbdfi_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before fbdfi is made visible.
function fbdfi_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to fbdfi (see VARARGIN)

% Choose default command line output for fbdfi
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes fbdfi wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = fbdfi_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

imshow('Jupiter_New_Horizons.jpg','parent',handles.axes1)
xlabel(handles.axes1,'X axis')
ylabel(handles.axes1,'Y axis')
camzoom(handles.axes1,.8)

for i=0:-10:-180
   view(handles.axes1,[i 90]);
   pause(.3)

end

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

t=0:.1:2*pi;
x=sin(t)
plot(handles.axes2,t,x);
grid minor
xlabel(handles.axes2,'X axis')
ylabel(handles.axes2,'Y axis')
camzoom(handles.axes2,.8)
for i=0:-10:-180
   view(handles.axes2,[i 90]);
   pause(.3)
end

希望这会有所帮助,

卡普拉'

【讨论】:

  • 谢谢它确实轮换了。但是,我在图中显示了两个轴。 [a,b]=uigetfile(['*.*','All Files']); img=imread([b a]); [r3,c3]=size(img) img = rgb2gray(img); imshow(img,'Parent',this.gui_h.axes1); camzoom(.8) % Rotate the axes changing the Azimuth value for i=0:-3:-180 view([i 90]); pause(.3) end
  • 代码旋转下一个没有图像的轴。当我尝试在axes2中加载图像时,它不会加载。有没有办法指定轴,例如:handles.axes1 或handles.axes2
  • 您可以尝试在对view的调用中指定要旋转的轴的句柄(例如view(axes_handle,[i 90])
  • 谢谢我更新到view(this.gui_h.axes1,[i 90]);。但是,它完全从 gui/图中消失了。我错过了一步吗?
  • 我创建了一个简单的 GUI,其中包含两个 axes 和两个 pushbuttons:一个按钮加载图像并转动轴,另一个在其他轴上绘制曲线并转动它。它有效,轴旋转正确。绘图和旋转的代码在 pushbutton 回调中。请检查更新答案。我不知道为什么你的 GUI 不起作用。可能是因为您管理handles 的方式吗? this.gui_h.axes1 是什么?
猜你喜欢
  • 1970-01-01
  • 2016-11-17
  • 1970-01-01
  • 1970-01-01
  • 2011-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多