2010-06-03 58 views
0

我需要在使用MATLAB创建的电影中放置背景图片?我如何在matlab中放入电影中的背景图片


我已张贴下面我如何产生一个电影在Matlab中的示例代码。我需要为这部电影添加背景图片。谢谢你的帮助。

for i=1:128 
    for j=1:128 
     p(i,j,:)=randn(1,200); 
    end 
end 
[u,v,w]=size(p); 

frm_r=1:128; 
frm_c=1:128; 

figure; j=1; 
for t=1:w 
    surface(frm_c,frm_r,p(:,:,t),'EdgeColor','none'); 
    pause(0.1) 
    colorbar; 
    F(j) = getframe; 
    j=j+1; 
end 
movie(F,1,50) 

回答

1

如果您有权访问创建影片的MATLAB代码,则可以将包含IMAGE或IMSHOW的轴作为背景,并使其顶部的轴为透明。

下面是一个简单的例子:

im = image; % create image object (default pic) 
imax = get(im,'parent'); % get image axes handle 
axis ij 
set(imax,'position',[0 0 1 1]) % make it to fill the whole figure 

ax = axes; % new axes 
h = plot(ax,rand(100),'ro'); % initial plot 
for i=1:20 
    set(h,'ydata',rand(100,1)); % change the data in a loop 
    pause(0.1) 
end 

你可以得到更好的答案,如果你表现出你的代码是如何创建的电影。

编辑

我在你的答案有点简化了代码。例如,你不需要循环来填充3D数组。而且你不需要在循环中重复表面功能。只需更改zdata属性。

试试这个代码(替代yourimage.jpg实际文件名):

p = randn(128,128,200); 
[u,v,w]=size(p); 
frm_r=1:128; 
frm_c=1:128; 

figure; 
im = imshow('yourimage.jpg'); % create and display image object from a file 
imax = get(im,'parent'); % get image axes handle 
set(imax,'position',[0 0 1 1]) % make it to fill the whole figure 

ax = axes('color','none'); % new axes 
hsurf = surface(frm_c,frm_r,p(:,:,1),'EdgeColor','none','Parent',ax); 
colorbar; 
xlim([1 u]) 
ylim([1 v]) 

j=1; 
for t=1:w 
    set(hsurf,'zdata',p(:,:,t)) 
    F(j) = getframe; 
    j=j+1; 
end 
movie(F,1,50)