图 6.5-10
【例6.5.4.3-3】本例目的:(A)理解贴片和边的透明度:本例使曲面上不同贴片(和边)取不同的透明度,每个贴片(和边)上各点的透明度相同。(B)指令搭配:只有当待透明化数据是“非标量”时,才能使用alpha('flat')或alpha('interp')。本例时由alpha(Z)把待透明化数据设置为矩阵的。(C)如何查询Alim和AlimMode属性。
[X,Y,Z]=peaks(20); surf(X,Y,Z); shading flat alpha(Z)
alpha('flat') Alimit=alim
alim_mode=alim('mode')
Alimit =
-6.3605 7.5561 alim_mode = auto
图 6.5-11
【例6.5.4.3-4】借助Alpha轴上下限设置改变曲面透明度。本例演示:指令alpha(options)是如何随输入宗量options的不同,而对不同的对象属性进行设置。
[X,Y,Z]=peaks(20); surf(X,Y,Z); shading flat alpha(Z)
Amin=-3;Amax=3; alim([Amin,Amax])
31
alpha('scaled') alpha('interp')
图 6.5-12
【例6.5.4.3-5】借助MATLAB提供的透明度表,设置曲面的透明度。本例演示:(A)V字型透明表:表有64个元素;第1和第64个元素透明度为1,即不透明;第32个元素透明度为0,即全透明。(B)待透明化数据是Z阵中大小不同的元素,因此纵坐标为0附近的曲面部分将几乎全透明,而上下峰几乎完全不透明。
clf,figure
[X,Y,Z]=peaks(20); surf(X,Y,Z); shading interp alpha(Z)
alpha('interp')
alphamap('vdown')
图 6.5-13
【例6.5.4.3-6】用透明度和色彩同时表现曲面的径向导数:导数大处颜色深、欠透明;导数小处颜色浅、较透明。注意AlphaData设置与Cdata的搭配。
figure(close)
x=3*pi*(-1:1/30:1);y=x;[X,Y]=meshgrid(x,y); R=sqrt(X.^2+Y.^2)+eps;Z=sin(R)./R; [dzdx,dzdy]=gradient(Z); dzdr=sqrt(dzdx.^2+dzdy.^2); surf(X,Y,Z,abs(dzdr)) shading interp colormap(spring) alphamap('rampup') alpha('color') alpha('interp')
32
图 6.5-14
6.6 图象
6.6.1 图象的类别和显示 6.6.2 图象的读写
6.6.2.1 图象数据的保存和提取 6.6.2.2 标准格式图象文件的读写
【例6.6.2.2-1】图象文件的读取和图象的显示 (1)
[X,cmap]=imread('trees.tif'); class(X)
image(X);colormap(cmap);axis image off ans = uint8
图 6.6-1
(2)
[X,cmap]=imread('saturn.tif'); cmap
33
imagesc(X);
colormap(gray); axis image off cmap = []
图 6.6-2
(3)
X=imread('flowers.tif');
imwrite(X,'ff.jpg','Quality',100) imfinfo('ff.jpg')
image(imread('ff.jpg')) axis image off ans =
Filename: 'ff.jpg'
FileModDate: '03-Mar-2002 13:42:30' FileSize: 193220 Format: 'jpg'
FormatVersion: '' Width: 500 Height: 362 BitDepth: 24
ColorType: 'truecolor' FormatSignature: ''
图 6.6-3
34
6.6.3 8位和16位图象
【例6.6.3.1-1】变址图象两种数据类型的转换。本例演示:(A)由位深度(BitDepth)可知存放图象数据的类型;(B)存放同一图象的unit8类数据和double类数据间的等价转换;(C)利用imwrite生成图象格式文件时默认地采用unit8类型存放图象数据。 (1)
imageinf=imfinfo('forest.tif') imageinf =
Filename: 'E:\\MATLAB6P1\\toolbox\\images\\imdemos\\forest.tif' FileModDate: '26-Oct-1996 06:11:14' FileSize: 124888 Format: 'tif' ????
BitDepth: 8 ????
Colormap: [256x3 double] ????
(2)
[X8,cmap]=imread('forest.tif'); subplot(1,2,1);
image(X);colormap(cmap);axis image off X64=double(X8)+1;subplot(1,2,2);
image(X64);colormap(cmap);axis image off
图 6.6-4
(3)
whos
Name Size Bytes Class
X8 301x447 134547 uint8 array X64 301x447 1076376 double array cmap 256x3 6144 double array imageinf 1x1 11250 struct array
Grand total is 271910 elements using 1239567 bytes
(4)
imwrite(X64,cmap,'myforest.jpg') imfinfo('myforest.jpg') ans =
Filename: 'myforest.jpg'
FileModDate: '03-Mar-2002 19:38:26' FileSize: 27716 Format: 'jpg'
FormatVersion: '' Width: 447 Height: 301 BitDepth: 24
ColorType: 'truecolor'
35