plot single analyze slice image --- vb_plot_3d_image(B,indx,vdim,mode) [strX,strY,strZ,B2] = vb_plot_3d_image(B,indx,vdim,mode,XYZ) --- Input B : 3D-image [NBx, NBy, NBz]. The coordinate system must be RAS. Note that the default of ANALYZE coordinate is LAS. indx : slice index in vdim-axis vdim : slice cut direction = 'x' : Sagittal cut : Y-Z plane = 'y' : Coronal cut : X-Z plane = 'z' : Transverse (Axial) cut : X-Y plane --- Optional input mode : 2D plot mode for X-Y = 0 : plot without transpose = 1 : plot by transposing 2D-image matrix XYZ = [Xmax Ymax Zmax] : 3D image size --- Output strX : 3D-axis direction for X-axis in 2D-plot image strY : 3D-axis direction for Y-axis in 2D-plot image strZ : 3D-axis direction for Z-axis in 2D-plot image B2 : 2D-image matrix written by M. Sato 2005-8-1 Modified by M Sato 2007-3-16 --- Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [strX,strY,strZ,B2] = vb_plot_3d_image(B,indx,vdim,mode,XYZ) 0002 % plot single analyze slice image 0003 %--- 0004 % vb_plot_3d_image(B,indx,vdim,mode) 0005 % [strX,strY,strZ,B2] = vb_plot_3d_image(B,indx,vdim,mode,XYZ) 0006 % 0007 % --- Input 0008 % B : 3D-image [NBx, NBy, NBz]. The coordinate system must be RAS. 0009 % Note that the default of ANALYZE coordinate is LAS. 0010 % indx : slice index in vdim-axis 0011 % vdim : slice cut direction 0012 % = 'x' : Sagittal cut : Y-Z plane 0013 % = 'y' : Coronal cut : X-Z plane 0014 % = 'z' : Transverse (Axial) cut : X-Y plane 0015 % --- Optional input 0016 % mode : 2D plot mode for X-Y 0017 % = 0 : plot without transpose 0018 % = 1 : plot by transposing 2D-image matrix 0019 % XYZ = [Xmax Ymax Zmax] : 3D image size 0020 % --- Output 0021 % strX : 3D-axis direction for X-axis in 2D-plot image 0022 % strY : 3D-axis direction for Y-axis in 2D-plot image 0023 % strZ : 3D-axis direction for Z-axis in 2D-plot image 0024 % B2 : 2D-image matrix 0025 % 0026 % written by M. Sato 2005-8-1 0027 % Modified by M Sato 2007-3-16 0028 %--- 0029 % 0030 % Copyright (C) 2011, ATR All Rights Reserved. 0031 % License : New BSD License(see VBMEG_LICENSE.txt) 0032 0033 if nargin < 2, indx = fix(NBx/2); end; 0034 if nargin < 3, vdim = 'x'; end; 0035 if nargin < 4, mode = 0; end; 0036 0037 indx = round(indx); 0038 0039 [NBx,NBy,NBz]=size(B); 0040 0041 if ~exist('XYZ', 'var'), XYZ = [NBx,NBy,NBz]; end; 0042 if length(XYZ) ~= 3, error('Image size must be 3dim'); end; 0043 0044 xdim = [0, XYZ(1)]; 0045 ydim = [0, XYZ(2)]; 0046 zdim = [0, XYZ(3)]; 0047 0048 % Normalization of voxel values 0049 B = B/max(B(:)); 0050 0051 % Analyze-slice-cut direction 0052 switch vdim, 0053 case 'x', 0054 % 'SAG' : Sagittal cut : Y-Z plane 0055 B2 = reshape(B(indx,:,:),NBy,NBz); 0056 valX = ydim; 0057 valY = zdim; 0058 strX = 'Y'; 0059 strY = 'Z'; 0060 strZ = 'X'; 0061 case 'y', 0062 % 'COR' : Coronal cut : X-Z plane 0063 B2 = reshape(B(:,indx,:),NBx,NBz); 0064 valX = xdim; 0065 valY = zdim; 0066 strX = 'X'; 0067 strY = 'Z'; 0068 strZ = 'Y'; 0069 case 'z', 0070 % 'TRN' : Transverse (Axial) cut : X-Y plane 0071 B2 = B(:,:,indx); 0072 valX = xdim; 0073 valY = ydim; 0074 strX = 'X'; 0075 strY = 'Y'; 0076 strZ = 'Z'; 0077 end; 0078 0079 % Reduction of dimension of voxel matrix 0080 B2 = squeeze(B2); 0081 0082 if mode==0 0083 % Flip 0084 B2 = B2'; 0085 0086 % Index color -> True color 0087 B3 = repmat(B2,[1 1 3]); 0088 0089 image(valX, valY, B3, 'CDataMapping','scaled'); 0090 set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual'); 0091 else 0092 % Index color -> True color 0093 B3 = repmat(B2,[1 1 3]); 0094 0095 str = strX; 0096 strX = strY; 0097 strY = str; 0098 0099 val = valX; 0100 valX = valY; 0101 valY = val; 0102 0103 image(valX, valY, B3, 'CDataMapping','scaled'); 0104 end 0105 0106 colormap('gray'); 0107 axis equal 0108 axis tight 0109 0110 return 0111 %-------------------------- 0112 % 0113 % IMAGE(X,Y,C) は、X と Y がベクトルのとき、C(1,1) と C(M,N) のピクセルの中 0114 % 心の位置を指定します。要素 C(1,1) は、(X(1)、Y(1))を中心とし、要素 C(M,N) 0115 % は(X(end)、Y(end))を中心とし、C の残りの要素の中心のピクセルは、 0116 % これらの2点の間に等間隔に設定される 0117 % 0118 % XDir, YDir, ZDir : {normal} | reverse 0119 % 値の増加する方向。Axesの値の増加する方向を制御するモード 0120 % 0121 % XLimMode, YLimMode, ZLimMode : {auto} | manual 0122 % Axesの範囲を設定するモード 0123 % プロットされるデータをベースに、MATLABがAxesの範囲を計算するか、または、 0124 % ユーザが、XLim, YLim, ZLimプロパティを使って明示的に値を設定するか