www.gusucode.com > 《matlab图像处理与界面编程宝典》秦襄培 编著,每章的MATLAB源代码程序 > 第3章/第3.4.4节中的代码.txt

    
load mri% 装入文件到MATLAB的工作空间,其命令形式为load filename
D = squeeze(D);% squeeze函数去除掉维数为1的那个维度,这里由128×128×1×27变为128×128×27
image_num = 8;%对image_num赋值
image(D(:,:,image_num)) %第8张图片,图片尺寸为128×128
axis image %加上坐标
colormap(map) %色彩索引图为map
x = xlim;%函数形式为xlim, ylim, zlim,设置或者查询坐标范围
y = ylim;
contourslice(D,[],[],image_num)%画第8张图的等高线图
axis ij
xlim(x)%设定x坐标范围和上一张图一致
ylim(y)%设定y坐标范围和上一张图一致
daspect([1,1,1])%设置或者查询坐标轴的外观比例
colormap('default')%色彩索引图为默认
phandles = contourslice(D,[],[],[1,12,19,27],8); 画第1,12,19,27张图的等高线图
view(3); axis tight
set(phandles,'LineWidth',2)%设置线宽
Ds = smooth3(D);%平滑三维数据
hiso = patch(isosurface(Ds,5),...%生成面片三维图像
	'FaceColor',[1,.75,.65],...%这里使用...进行程序换行连续
	'EdgeColor','none');
hcap = patch(isocaps(D,5),...
	'FaceColor','interp',...
	'EdgeColor','none');
colormap(map)
colormap(map)
view(45,30) 
axis tight %设置坐标轴范围为数据范围
daspect([1,1,.4])%设置坐标轴显示比例,这里Z轴比例为1:0.4
lightangle(45,30); %设置光线入射角度
set(gcf,'Renderer','zbuffer'); lighting phong%得到当前句柄,设置光照类型
isonormals(Ds,hiso)
% 句法为n = isonormals(V,p),计算句柄p包含面片向量的法线
set(hcap,'AmbientStrength',.6)%设置环境直接反射强度
set(hiso,'SpecularColorReflectance',0,'SpecularExponent',50)
%设置对象镜面反射光的颜色程度和对象镜面反射高光的尺寸