下面來介紹一下經典的功夫熊貓的動作在MATLAB中實作動畫制作,達到顯示的效果,具體如下:
1、首先在MATLAB的主界面編輯器中寫入下列代碼,具體如下:
clc;close all;clear all;figure(1);
%制作電影動畫
m=moviein(28); %配置設定存儲幀的記憶體
a0=int2str(0);
for i=1:9 % 依次讀入1-9張數字圖像
a=int2str(i);
a1=strcat('G:\KonghuPanda\KonghuPanda',a0,a0,a,'.jpg');
X1=imread(a1);imshow(X1);m(i)=getframe;
end
for i=10:28 % 依次讀入10-28張數字圖像
a2=int2str(i);
a3=strcat('G:\KonghuPanda\KonghuPanda',a0,a2,'.jpg');
X2=imread(a3);imshow(X2);m(i)=getframe;
end
movie(m,8); %播放動畫
%輸出各個電影幀
figure(2);
for i=1:9
subplot(7,4,i);
a=int2str(i);
a1=strcat('G:\KonghuPanda\KonghuPanda',a0,a0,a,'.jpg');
X1=imread(a1);
image(X1);axis off;box off;
a4=int2str(i);
a5=strcat('第',a4,'幀');
title(a5,'fontsize',9,'fontname','隸書');
end
for i=10:28
subplot(7,4,i);
a2=int2str(i);
a3=strcat('G:\KonghuPanda\KonghuPanda',a0,a2,'.jpg');
X2=imread(a3);
image(X2);axis off;box off;
a6=int2str(i);
a7=strcat('第',a6,'幀');
title(a7,'fontsize',9,'fontname','隸書');
end
2、命名儲存代碼至自定義路徑下,點選運作,結果如下(由于是動态圖,我隻截取了部分,大家可以運作代碼後觀看完整的)

如圖所示,前面幾張圖是動畫圖截取部分,後面是從第1幀到 第28幀的所有圖像,所謂動畫制作,其實就是将每一幀的圖像通過設定一定的時延來呈現出來,時間的長短和圖檔的畫質就決定了動畫品質的高低,請大家繼續關注!!!