Home > SurfStat > SurfStatViews.m

SurfStatViews

PURPOSE ^

Viewer for slices of volumetric data.

SYNOPSIS ^

function SurfStatViews( data, vol, z, layout );

DESCRIPTION ^

Viewer for slices of volumetric data.

 Usage: SurfStatViews( data, vol [, z [, layout ]] );

 data       = n x v matrix of data if k=1, or n x v x k array of data if 
              k>1, or a memory map of same.
 vol.lat    = nx x ny x nz logical array, 1=in, 0=out.
 vol.vox    = 1 x 3 vector of voxel sizes in mm.
 vol.origin = position in mm of the first voxel.
 z          = 1 x s vector of z coordinates of slices. Default is 0.
              The nearest slices are displayed. 
 layout     = matrix of indices from 1:(n*k*s) specifying which slice
              appears in position layout(i,j), with 0 for an empty image.
              Default is reshape(1:(n*k*s),n,k*s).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function SurfStatViews( data, vol, z, layout );
0002 
0003 %Viewer for slices of volumetric data.
0004 %
0005 % Usage: SurfStatViews( data, vol [, z [, layout ]] );
0006 %
0007 % data       = n x v matrix of data if k=1, or n x v x k array of data if
0008 %              k>1, or a memory map of same.
0009 % vol.lat    = nx x ny x nz logical array, 1=in, 0=out.
0010 % vol.vox    = 1 x 3 vector of voxel sizes in mm.
0011 % vol.origin = position in mm of the first voxel.
0012 % z          = 1 x s vector of z coordinates of slices. Default is 0.
0013 %              The nearest slices are displayed.
0014 % layout     = matrix of indices from 1:(n*k*s) specifying which slice
0015 %              appears in position layout(i,j), with 0 for an empty image.
0016 %              Default is reshape(1:(n*k*s),n,k*s).
0017 
0018 if isnumeric(data)
0019     [n,v,k]=size(data);
0020 else
0021     datam=data;
0022     ss=datam.Format{2};
0023     if length(ss)==2
0024         ss=ss([2 1]);
0025         k=1;
0026     else
0027         ss=ss([3 1 2]);
0028         k=ss(3);
0029     end
0030     n=ss(1);
0031     v=ss(2);
0032 end
0033 
0034 [nx,ny,nz]=size(vol.lat);
0035 if nargin<3 | isempty(z)
0036     z=0;
0037 end
0038 s=length(z);
0039 if nargin<4
0040     layout=reshape(1:(n*k*s),n,k*s);
0041 end
0042 [lx,ly]=size(layout);
0043 m=zeros(lx*ny+lx+1,ly*nx+ly+1)+NaN;
0044 vs=[0; squeeze(cumsum(sum(sum(vol.lat))))];
0045 for i=1:lx
0046     for j=1:ly
0047         if layout(i,j)>0
0048             [n1,k1,s1]=ind2sub([n,k,s],layout(i,j));
0049             slice=round((z(s1)-vol.origin(3))/(vol.vox(3)+(vol.vox(3)==0)))+1;
0050             slice=max(min(slice,nz),1);
0051             v1=vs(slice)+1;
0052             v2=vs(slice+1);
0053             d=zeros(nx,ny)+NaN;
0054             if isnumeric(data)
0055                 d(vol.lat(:,:,slice))=data(n1,v1:v2,k1);
0056             else
0057                 if length(ss)==2
0058                     d(vol.lat(:,:,slice))=datam.Data(1).Data(v1:v2,n1);
0059                 else
0060                     d(vol.lat(:,:,slice))=datam.Data(1).Data(v1:v2,k1,n1);
0061                 end
0062             end
0063             m((1:ny)+(ny+1)*(i-1)+1,(1:nx)+(nx+1)*(j-1)+1)=flipud(d');
0064         end
0065     end
0066 end
0067 m(isnan(m))=min(min(min(m(~isnan(m)))));
0068 
0069 imagesc((1:size(m,2))*vol.vox(1),(1:size(m,1))*vol.vox(2),m); 
0070 for i=1:lx
0071     for j=1:ly
0072         if layout(i,j)>0
0073             [n1,k1,s1]=ind2sub([n,k,s],layout(i,j));
0074             h=text(((nx+1)*(j-1)+1)*vol.vox(1),...
0075                 ((ny+1)*(i)+1)*vol.vox(2),num2str(layout(i,j)));
0076             set(h,'Color','white','VerticalAlignment','bottom');
0077         end
0078     end
0079 end
0080 colorbar; colormap(spectral(256));
0081 xlabel('x'); ylabel('y'); 
0082 axis equal; axis off; 
0083 
0084 background='white';
0085 whitebg(gcf,background);
0086 set(gcf,'Color',background,'InvertHardcopy','off');
0087 
0088 set(gcf,'PaperPosition',[0.25 2.5 6 4.5]);
0089 
0090 return
0091 end

Generated on Fri 26-Sep-2008 14:05:29 by m2html © 2003