基于Matlab三维切片数据绘图以及自由旋转

例子1

slice用法介绍

load mri
D = double(squeeze(D));
D(D==0)=nan;
h = slice(D, [], [], 1:size(D,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.4)

在这里插入图片描述

例子2

官方文档介绍

[x,y,z] = meshgrid(-1.25:.1:-.25,-2:.2:2,-2:.1:2);
v = x.*exp(-x.^2-y.^2-z.^2);
% 指定切片的位置在xyz轴
h = slice(x,y,z,v,[-1 -.75 -.5],[],[0]);
set(h,'EdgeColor','none',...
'FaceColor','interp',...
'FaceAlpha','interp')
alpha('color')

alphamap('rampdown')
alphamap('increase',.1)
colormap hsv

在这里插入图片描述

pcolor3效果

%% example1
[x,y,z] = meshgrid(-2:.05:2,-2:.1:2,-2:.1:2);
v = x.*exp(-x.^2-y.^2-z.^2) + 1;
figure
pcolor3(v)
axis tight

在这里插入图片描述

%% example2
figure
pcolor3(x,y,z,v,'edgealpha',.1)
rgbmap('blue','white','red')
colorbar
caxis([0.8 1.2])
% camlight
view(160,36)

在这里插入图片描述

%% example3
figure
pcolor3(x,y,z,v,'cubic','edgealpha',.1)
% pcolor3(x,y,z,v,'alphalim',[1 1.2],'cubic','edgealpha',.1)
rgbmap('blue','white','red')
colorbar
caxis([0.8 1.2])
% camlight
view(160,36)

在这里插入图片描述

%% example4
[lon,lat,z] = meshgrid(-180:3:180,-80:2:80,0:100:2000);
T = 30 - .1*abs(lat) - .01*z + sind(lon);
figure
pcolor3(lon,lat,z,T,'direct')
% pcolor3(lon,lat,z,T,'direct','alphalim','auto')
% format:
xlabel('longitude')
ylabel('latitude')
zlabel('elevation (m)')
axis tight
set(gca,'xtick',[-180 -90 0 90 180],...
    'ytick',[-45 0 45])
c = load('coast.mat');
plot(c.long,c.lat)

在这里插入图片描述

旋转绘图

方法1 spinningGIF

load mri
D = double(squeeze(D));
D(D==0)=nan;
h = slice(D, [], [], 1:size(D,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.4)

spinningGIF('123')
% spinningGIF(fname): makes a spinning GIF of the current plot and saves it
% Usage: make your 3D plot (using plot3(...) or scatter3(...) etc.) and
% then call SpinningGIF with the file name that you want
function spinningGIF(fname)
    axis off
%     view(0,10)
    center = get(gca, 'CameraTarget');
    pos = get(gca, 'CameraPosition');
    radius = norm(center(1:2) - pos(1:2));
    angles = 0:0.02*pi:2*pi;
    for ii=1:length(angles)
       angle = angles(ii);
       set(gca, 'CameraPosition', [center(1) + radius * cos(angle),...
                                   center(2) + radius * sin(angle),...
                                   pos(3)]);
       drawnow;
       frame = getframe(1);
       im = frame2im(frame);
       [imind,cm] = rgb2ind(im,256);
       if ii == 1
           imwrite(imind,cm,fname,'gif', 'Loopcount',inf);
       else
           imwrite(imind,cm,fname,'gif','WriteMode','append','DelayTime', 0.25);
       end
    end
end

方法2

OptionZ.FrameRate=15;OptionZ.Duration=5.5;OptionZ.Periodic=true;
CaptureFigVid([-20,10;-110,10;-190,80;-290,10;-380,10], 'WellMadeVid',OptionZ)

方法3

load mri
D = double(squeeze(D));
D(D==0)=nan;
h = slice(D, [], [], 1:size(D,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.4)

for az=0:5:355
    view(az,36)
    drawnow;
end
  • 7
    点赞
  • 70
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值