matlab如何显示三维体数据

在显示三维体图像的时候,我们一般都用专业软件来显示,这样有时候挺麻烦的,最近整理了一个关于matlab显示三维体的程序;

首先我们先实现一个读取bin二进制文件的matlab函数GetBin3DData;


%%%FileName为二进制文件的位置,InLineLen,CrossLineLen,SampleLineLen为三维体的三个方向的维度,Vol为三维体的大小


function Vol = GetBin3DData(FileName,InLineLen,CrossLineLen,SampleLineLen)
Vol = zeros(InLineLen,CrossLineLen,SampleLineLen);%返回三维数据体
fid = fopen(FileName);
for i = 1:1:InLineLen
    for j = 1:1:CrossLineLen
        if(i == InLineLen && j == CrossLineLen)
            return;
        end
        [Vol(i,j,:) nCount] = fread(fid,SampleLineLen,'float');
        if(nCount ~= SampleLineLen)
            fprintf('读取三维数据错误! 请检查!');
        end
    end
end
fclose(fid);
end


% function Vec = GetBin3DData(FileName,InLineLen,CrossLineLen)
% Vec = zeros(InLineLen,CrossLineLen);%返回二维数据体
% fid = fopen(FileName,'r');
% for i = 1:1:InLineLen
%         [Vec(i,:) nCount] = fread(fid,CrossLineLen,'double');
%         if(nCount ~= CrossLineLen)
%             fprintf('读取二维数据错误! 请检查!');
%         end
% end
% fclose(fid);
% end


以上为主要函数


FileName = 'data.bin'
InLine = 200;
CroLine = 200;
TimeLine = 51;
Vol = GetBin3DData(FileName,InLine,CroLine,TimeLine);
x = 1 : InLine;
y = 1 : CroLine;
z = 1 : TimeLine;
temp = Vol;
x = 1 : InLine;
y = 1 : CroLine;
z = 1 : TimeLine;
V3D_FIGUREID=figure();
axis equal;
V3D_AXESID=cla;
% 3D-View
view(3);
% Eigenschaften der Achsen setzen
set(V3D_AXESID,'Layer','top');          % Achsen 黚er Grafik zeichnen
set(V3D_AXESID,'Box','on');             % Achsen-Box an


cmin=min(temp(:));
cmax=max(temp(:));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%显示三维地震图
hold on
V3D_SLICE = slice(temp,x,y,z);


set(V3D_SLICE,'FaceColor','interp'); 
set(V3D_SLICE,'EdgeColor','interp');
set(V3D_SLICE,'FaceLighting','none');
set(V3D_SLICE,'Tag','V3D:SLICE');




hold off






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%显示切面,其中Xslice,Yslice,Zslice为切面维度
delete(findobj(V3D_FIGUREID,'Tag','V3D:SLICE'));


figure(V3D_FIGUREID);


hold on
Xslice = 1;
Yslice = [];
Zslice = 20;


V3D_SLICE = slice(x,y,z,temp,Xslice,Yslice,Zslice,'linear');
set(V3D_SLICE,'FaceColor','interp'); 
set(V3D_SLICE,'EdgeColor','interp');
set(V3D_SLICE,'FaceLighting','none');
set(V3D_SLICE,'FaceAlpha','interp');
set(V3D_SLICE,'EdgeAlpha','interp'); 
set(V3D_SLICE,'Tag','V3D:SLICE');
slud.method = 1;
slud.EdgeColor = 'interp';
slud.EdgeColor_value = 11;
slud.facecolor = 'interp';
slud.facecolor_value = 11;
slud.lighting = 1;
slud.alpha_single = 1;
slud.alpha = 3;
slud.x = Xslice;
slud.y = Yslice;
slud.z = Zslice;
set(V3D_SLICE,'userdata',slud);


if (slud.alpha==2 | slud.alpha==3) 
    temp=findobj(V3D_FIGUREID,'Tag','V3D:SLICE');
    for i=1:length(temp)
        set(temp(i),'AlphaData',get(temp(i),'CData'));
    end
end
    
% set(V3D_SLICE,'EdgeLighting','none');

% set(V3D_SLICE,'FaceAlpha','interp');
% set(V3D_SLICE,'EdgeAlpha','interp'); 
% set(V3D_SLICE,'Tag','V3D:SLICE');
% % set(V3D_SLICE,'userdata',objud);
% % alpha('color');
% alphamap('increase',1);

% % Colorbar setzen
% % V3D_COLORBAR=colorbar;
% % set(V3D_COLORBAR,'Tag','V3D:COLORBAR');

% % Minimum und Maximum Color setzen
% set(V3D_AXESID,'CLim',[cmin cmax]);
hold off                           


%%%%这是三维体数据



%%%%%这是显示三维切面的样子



你可能感兴趣的:(数据挖掘,统计分类方法)