2017-02-26 84 views
0

我正在嘗試旋轉一個名爲axes1的整個軸。在Matlab指南中旋轉整個軸

   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);,這沒有效果。它只是忽略了陳述,並繼續進行其他任務。有沒有辦法旋轉整個軸?

+0

可以使用:'I = imrotate(frame2im(的getFrame(GCA)),30);',但是旋轉只是可視的(結果是圖像,而不是功能軸)。 – Rotem

+0

它似乎只是旋轉軸而不是軸的圖像。除此之外,圖像被表示爲具有黑色背景的白色正方形 – Sade

+0

我想旋轉整個軸而不僅僅是軸內圖像的原因是因爲旋轉軸不會在圖像旋轉時改變圖像的大小。在一個軸上旋轉圖像會改變尺寸。如果有辦法解決這個問題,它也可以是一個選項? – Sade

回答

2

可以使用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 

enter image description here

這也適用於標準樣:

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 

enter image description here

編輯以下

我已經創建了一個評論簡單的GUI具有兩個axes和兩個pushbutton具有以下tag

  • 軸#1:axes1
  • 軸#2:axes2
  • 按鈕#1:pushbutton1
  • 按鈕#2:pushbutton2

callback按鈕1軸上加載圖像1,轉動軸。

的的callbackpushbutton2地塊在axes2的曲線,所述轉動軸。

的GUI工作正常,axers旋轉預期。

這是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 

enter image description here

希望這有助於

Qapla」

+0

謝謝你它旋轉。但是,我在圖中顯示了兩個軸。 '[a,b] = uigetfile(['*。*','所有文件']); img = imread([b a]); (img) img = rgb2gray(img); imshow(img,'Parent',this.gui_h.axes1); camzoom(.8) %旋轉軸改變方位角值 (i = 0:-3:-180) view([i 90]); 暫停(.3) 結束# – Sade

+0

代碼旋轉下一個沒有圖像的軸。當我嘗試在axis2中加載圖像時,它不加載。是否有一種方法來指定座標軸,例如:handles.axes1或handles.axes2 – Sade

+0

您可以嘗試在調用'view'時指定要旋轉的軸的柄(例如'view(axes_handle,[i 90]) '。 –