function view_slices(input_file, input_thresh, mask_file, mask_thresh, slices, frame) %VIEW_SLICES displays the slices in a 3D volume. % % VIEW_SLICES( INPUT_FILE [, MASK_FILE [, MASK_THRESH [, SLICES [, FRAME]]]]) % % INPUT_FILE is the name of a single image file with multiple frames. % Coordinates are in voxels, starting at 0, as in 'register'. Since matlab % can't reverse axis labels, they are negative if the step sizes are negative % - ignore the minus signs. % % MASK_FILE is a mask file. If empty, it is ignored. Default is []. % % MASK_THRESH defines the search volume as the first frame of MASK_FILE % > MASK_THRESH. If MASK_THRESH is a vector [a b], a<=b, then mask % is a < MASK_FILE <= b. Default is 0. % % SLICES is a vector of desired slices starting at 0, as in 'register', % displayed in the top left. If SLICES is a single slice, then axis values % are given in voxels, starting at 0, as in 'register'. Since matlab % can't reverse axis labels, they are negative if the step sizes are negative % - ignore the minus signs. Default is 0:numslices-1, i.e. all the slices. % % FRAME is the desired frame number. Default is 1. %############################################################################ % COPYRIGHT: Copyright 2002 K.J. Worsley, % Department of Mathematics and Statistics, % McConnell Brain Imaging Center, % Montreal Neurological Institute, % McGill University, Montreal, Quebec, Canada. % worsley@math.mcgill.ca % % Permission to use, copy, modify, and distribute this % software and its documentation for any purpose and without % fee is hereby granted, provided that this copyright % notice appears in all copies. The author and McGill University % make no representations about the suitability of this % software for any purpose. It is provided "as is" without % express or implied warranty. %############################################################################ % Defaults: if nargin < 2 mask_file=[] end if nargin < 3 mask_thresh=0 end if nargin < 5 frame=1 end d=fmris_read_image(input_file,0,0); numslices=d.dim(3) numys=d.dim(2) numxs=d.dim(1) ext=input_file((length(input_file)-2):length(input_file)); isanalyze= all(ext=='img') if nargin < 4 slices=(1:numslices)-1 end if ~isempty(mask_file) mask_thresh1=mask_thresh(1); if length(mask_thresh)>=2 mask_thresh2=mask_thresh(2); else mask_thresh2=Inf; end m=fmris_read_image(mask_file,slices+1,1); m.data= (m.data>mask_thresh1 & m.data<=mask_thresh2); xf=find(max(max(m.data,[],2),[],3)); xr=min(xf):max(xf); yf=find(max(max(m.data,[],1),[],3)); yr=min(yf):max(yf); else xr=1:numxs; yr=1:numys; end nx=length(xr); ny=length(yr); nslices=length(slices); if nslices>1 mx=ceil(sqrt(nx*ny*nslices)/nx); my=ceil(nslices/mx); M=zeros(mx*nx,my*ny).*NaN; for i=1:mx for j=1:my islice=i+(my-j)*mx; if islice<=nslices slice=slices(islice)+1; d=fmris_read_image(input_file,slice,frame); v=d.data(xr,yr); if ~isempty(mask_file) v(m.data(xr,yr,islice)==0)=mask_value; end if d.vox(1)<0 & isanalyze v=flipdim(v,1); end if d.vox(2)<0 & isanalyze v=flipdim(v,2); end M((i-1)*nx+(1:nx),(j-1)*ny+(1:ny))=v; end end end M(isnan(M))=min(min(M)); imagesc(M'); axis xy; axis off; colorbar; title([input_file ', frame ' num2str(frame)]); for i=1:mx for j=1:my islice=i+(my-j)*mx; if islice<=nslices slice=slices(islice); text((i-1)*nx+nx*.05,(j-1)*ny+ny*.9,num2str(slice),'Color','w'); end end end else d=fmris_read_image(input_file,slices+1,frame); v=d.data(xr,yr); if ~isempty(mask_file) v(m.data(xr,yr,1)==0)=mask_value; end if d.vox(1)<0 & isanalyze v=flipdim(v,1); end if d.vox(2)<0 & isanalyze v=flipdim(v,2); end if d.vox(1)>0 xr=xr-1; xlab='x'; else xr=-(d.dim(1)-xr); xlab='-x'; end if d.vox(2)>0 yr=yr-1; ylab='y'; else yr=-(d.dim(2)-yr); ylab='-y'; end v(isnan(v))=min(min(v)); imagesc(xr,yr,v'); axis xy; grid on; xlabel(xlab); ylabel(ylab); colorbar; title([input_file ', slice ' num2str(slices) ', frame ' num2str(frame)]); end return input_file='c:/keith/results/ha_100326_hmw_mag_t.mnc'; mask_file='c:/keith/data/brian_ha_19971124_1_100326_mri_MC.mnc'; mask_thresh=fmri_mask_thresh(mask_file); plot([1 2]) text(1.5,1.5,'h','Color','r'); i=1 j=1 viewslices(input_file, mask_file, mask_thresh, slices, frame) viewslices(input_file, mask_file, mask_thresh,1:5) viewslices(input_file, mask_file, mask_thresh) viewslices(mask_file, mask_file, mask_thresh,1:3)