2013-07-26 27 views

回答

4

提到這一點:

How do I add a background image to my GUI or figure window?

我只是改變了命令 - >現與圖像軸在上面。試試下面的代碼:

% This creates the 'background' axes 
ha = axes('units','normalized', ... 
'position',[0.3,0.35,0.4,0.4]); 

% Load in a background image and display it using the correct colors 
% The image used below, is in the Image Processing Toolbox. If you do not have 
% access to this toolbox, you can use another image file instead. 
I=imread('eight.tif'); 
hi = imagesc(I) 
colormap gray 

% Turn the handlevisibility off so that we don't inadvertently plot into the axes again 
% Also, make the axes invisible 
set(ha,'handlevisibility','off', ... 
'visible','off') 

% Now we can use the figure, as required. 
% For example, we can put a plot in an axes 
axes('position',[0 0 1 1]) 
plot(rand(10)) 

% this creates transparency, you probably dont need it: 
set(hi,'alphadata',.5) 
% move the image to the top: 
uistack(ha,'top'); 

結果(不透明度)應該是這樣的:

enter image description here

0

非常感謝,這是非常有益的。 因此我做了一個功能

function legend_Image(Image_file,Fig_position,reduc_fact) 
% legend_Image(Image_file,Fig_position,reduc_fact) 
% Image_file= Image File name (full) 
% Fig_position: position on figure [1 2 3 4]= [U/L U/R D/R D/L] 
% reduc_fact : Ratio Image_size/Figure/size 

%% Figure example 
% hist(rand(1,2000),100); 
Dim1=get(gca,'position'); 
L =Dim1(1); D=Dim1(2); W=Dim1(3); H=Dim1(4); 
%% 
% Calculate the Image position on figure 
% reduction factor of the size 
im_W=W/reduc_fact; 
im_H=H/reduc_fact; 

switch Fig_position 
    case 1 % Position 1 : Upper/Left 
im_L=L; 
im_D=D+H-im_H; 
    case 2 % Position 2 : Upper/Right 
im_L=L+W-im_W; 
im_D=D+H-im_H; 
    case 3 % Position 3 : Down/Right 
im_L=L+W-im_W; 
im_D=D; 
    case 4 % Position 4 : Down/Left 
im_L=L; 
im_D=D; 
end 
ha = axes('units','normalized', ... 
'position',[im_L im_D im_W im_H]); 
%% 
% Load in a background image and display it using the correct 
I=imread(Image_file); 
hi = imagesc(I); 
% colormap gray 
%% 
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again 
% Also, make the axes invisible 
set(ha,'handlevisibility','off','visible','off'); 
%% I am not sur this is necessary !! 
% this creates transparency, you probably dont need it: 
% set(hi,'alphadata',.5) 
% % move the image to the top: 
% uistack(ha,'top'); 
%% 
end