Home > vbmeg > functions > plotfunc > subdirectory > vb_plot_3d_image.m

vb_plot_3d_image

PURPOSE ^

plot single analyze slice image

SYNOPSIS ^

function [strX,strY,strZ,B2] = vb_plot_3d_image(B,indx,vdim,mode,XYZ)

DESCRIPTION ^

 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
 Modified by M Sato  2015-11-27 (Normalization changed)
---

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 % Modified by M Sato  2015-11-27 (Normalization changed)
0029 %---
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 if nargin < 2, indx = fix(NBx/2); end;
0035 if nargin < 3, vdim = 'x'; end;
0036 if nargin < 4, mode = 0; end;
0037 
0038 indx = round(indx);
0039 
0040 [NBx,NBy,NBz]=size(B);
0041 
0042 if ~exist('XYZ', 'var'), XYZ = [NBx,NBy,NBz]; end;
0043 if length(XYZ) ~= 3, error('Image size must be 3dim'); end;
0044 
0045 xdim = [0, XYZ(1)];
0046 ydim = [0, XYZ(2)];
0047 zdim = [0, XYZ(3)];
0048 
0049 % Normalization of voxel values
0050 bmin = min(B(:));
0051 
0052 if bmin >= 0
0053     B = B/max(B(:)); 
0054 else
0055     % image with negative values
0056     B = (B - bmin)/(max(B(:)) - bmin);
0057 end
0058 
0059 % Analyze-slice-cut direction
0060 switch    vdim,
0061 case    'x',
0062  % 'SAG' : Sagittal cut : Y-Z plane
0063  B2   = reshape(B(indx,:,:),NBy,NBz);
0064  valX = ydim;
0065  valY = zdim;
0066  strX = 'Y';
0067  strY = 'Z';
0068  strZ = 'X';
0069 case    'y',
0070  % 'COR' : Coronal cut : X-Z plane
0071  B2   = reshape(B(:,indx,:),NBx,NBz);
0072  valX = xdim;
0073  valY = zdim;
0074  strX = 'X';
0075  strY = 'Z';
0076  strZ = 'Y';
0077 case    'z',
0078  % 'TRN' : Transverse (Axial) cut : X-Y plane
0079  B2   = B(:,:,indx);
0080  valX = xdim;
0081  valY = ydim;
0082  strX = 'X';
0083  strY = 'Y';
0084  strZ = 'Z';
0085 end;
0086 
0087 % Reduction of dimension of voxel matrix
0088 B2 = squeeze(B2); 
0089 
0090 if mode==0
0091   % Flip
0092   B2 = B2';
0093   
0094   % Index color -> True color
0095   B3 = repmat(B2,[1 1 3]);
0096 
0097   image(valX, valY, B3, 'CDataMapping','scaled');
0098   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual');
0099 else
0100   % Index color -> True color
0101   B3 = repmat(B2,[1 1 3]); 
0102   
0103   str  = strX;
0104   strX = strY;
0105   strY = str;
0106     
0107   val  = valX;
0108   valX = valY;
0109   valY = val;
0110 
0111   image(valX, valY, B3, 'CDataMapping','scaled');
0112 end
0113 
0114 colormap('gray');
0115 axis equal
0116 axis tight
0117 
0118 return
0119 %--------------------------
0120 %
0121 % IMAGE(X,Y,C) は、X と Y がベクトルのとき、C(1,1) と C(M,N) のピクセルの中
0122 %  心の位置を指定します。要素 C(1,1) は、(X(1)、Y(1))を中心とし、要素 C(M,N)
0123 %  は(X(end)、Y(end))を中心とし、C の残りの要素の中心のピクセルは、
0124 %  これらの2点の間に等間隔に設定される
0125 %
0126 % XDir, YDir, ZDir  : {normal} | reverse
0127 %  値の増加する方向。Axesの値の増加する方向を制御するモード
0128 %
0129 % XLimMode, YLimMode, ZLimMode : {auto} | manual
0130 %  Axesの範囲を設定するモード
0131 %  プロットされるデータをベースに、MATLABがAxesの範囲を計算するか、または、
0132 %  ユーザが、XLim, YLim, ZLimプロパティを使って明示的に値を設定するか

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005