Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


DisplayAfniSlice.m

Go to the documentation of this file.
00001 function [err] = DisplayAfniSlice (Slc, Opt)
00002 %
00003 %   [err] = DisplayAfniSlice (Slc, Opt)
00004 %
00005 %Purpose:
00006 %      
00007 %    OBSOLETE,  see DispAFNISlice
00008 %    the function is left here for backward compatibility
00009 %
00010 %   Display slices a la AFNI.
00011 %   
00012 %   
00013 %Input Parameters:
00014 %   Slc is a structure obtained from the output of function GetAfniSlice
00015 %       
00016 %   Opt is a structure wth the following fields
00017 %      .fhandle: figure handle, default is current figure
00018 %      .subplot: (2x1 integer vector) number of images per figure
00019 %      .colrange: (2x1 vector) the percentile of values to map to the color
00020 %             maps. A la Afni, [0 0]  for min-max, [2 98] to match afni's window 
00021 %      .plane string containing the plane displayed (same as in GetAfniSlice).
00022 %      .Info is the structure returned from BrikInfo
00023 %      .iSlc is the vector containing the slice indices used by GetAfniSlice       
00024 %  
00025 %Output Parameters:
00026 %   err : 0 No Problem
00027 %       : 1 Mucho Problems
00028 %   
00029 %   
00030 %      
00031 %Key Terms:
00032 %   
00033 %More Info :
00034 %   GetAfniSlice
00035 %   Test_GetAfniSlice
00036 %   
00037 %  DispAFNISlice, quite better.
00038 %
00039 %     Author : Ziad Saad
00040 %     Date : Mon Aug 28 11:47:32 PDT 2000
00041 %     LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00042 
00043 
00044 %Define the function name for easy referencing
00045 FuncName = 'DisplayAfniSlice';
00046 
00047 %Debug Flag
00048 DBG = 1;
00049 
00050 %initailize return variables
00051 err = 1;
00052 
00053 
00054 %if (~isfield(Opt,'') | isempty(Opt.)), Opt. = ; end
00055 if (~isfield(Opt,'fhandle') | isempty(Opt.fhandle)),    Opt.fhandle = gcf; end
00056 if (~isfield(Opt,'colrange') | isempty(Opt.colrange)),  Opt.colrange = [0 0]; end
00057 if (~isfield(Opt,'subplot') | isempty(Opt.subplot)),    Opt.subplot = [1 1]; end
00058 if (~isfield(Opt,'plane') | isempty(Opt.plane)),        err = ErrEval(FuncName, 'Err_must specify plane'); return; end
00059 if (~isfield(Opt,'Info') | isempty(Opt.Info)),  err = ErrEval(FuncName, 'Err_must specify BRIK Info'); return; end
00060 if (~isfield(Opt,'iSlc') | isempty(Opt.iSlc)),  err = ErrEval(FuncName, 'Err_must specify slice numbers'); return; end
00061 
00062 switch Opt.plane,
00063         case 'Ax',
00064                 planename = 'Axial';
00065         case 'Sa',
00066                 planename = 'Sagittal';
00067         case 'Co',
00068                 planename = 'Coronal';
00069 end 
00070 
00071 %number of slices
00072         szslc = size(Slc.M);
00073         prod(Opt.subplot);
00074         
00075 %make sure enough subplots are there
00076 if (prod(Opt.subplot) < szslc(3)),
00077         err= ErrEval(FuncName,'Err_Not enough subplots to display all slices');
00078         return;
00079 end
00080 
00081 % perform required scaling;     
00082 %I'd like to normalize to cover the color map
00083 %from 0 to the number of colors in the map
00084         map = colormap;
00085         nmap = max(size(map));
00086         lb = 0; 
00087         nM = prod(szslc);
00088         
00089         if (Opt.colrange(1) | Opt.colrange(2)), %not all points are to be scaled
00090                 M = reshape(Slc.M,[nM 1]);
00091                 [Msort, iMsort] = sort(M); 
00092                 lbval = Msort(round(Opt.colrange(1).*nM./100));
00093                 ubval = Msort(round(Opt.colrange(2).*nM./100));
00094                 iToScale = find (Msort >= lbval & Msort <= ubval);
00095                 
00096                 Mmin = min ( Msort(iToScale) );
00097                 Mmax = max ( Msort(iToScale) );
00098                 if (Mmin == Mmax),
00099                         Slc.M = ones(szslc).*nmap;
00100                 else
00101                         M(iMsort(1:min(iToScale)-1)) = lb;
00102                         M(iMsort(iToScale)) = (((M(iMsort(iToScale)) - Mmin) ./ (Mmax - Mmin)) .* (nmap-lb)) + lb;
00103                         M(iMsort(max(iToScale)+1:nM)) = nmap;
00104                         Slc.M = reshape(M,szslc);
00105                 end
00106         else
00107                 Mmin = min (Slc.M(:));
00108                 Mmax = max (Slc.M(:));
00109                 if (Mmin == Mmax),
00110                         Slc.M = ones(szslc).*nmap;
00111                 else
00112                         Slc.M = (((Slc.M - Mmin) ./ (Mmax - Mmin)) .* (nmap-lb)) + lb;
00113                 end
00114         end
00115 
00116         
00117 cf = figure(Opt.fhandle); clf
00118 stit = sprintf ('%s--- %s', Opt.Info.RootName, planename);
00119 set (cf,'Name',stit);
00120 
00121 nslc = size(Slc.M,3);
00122 for (i=1:1:nslc),
00123         subplot (Opt.subplot(1), Opt.subplot(2), i);
00124         image (Slc.M(:,:,i));
00125         axis equal;
00126         stit = sprintf('Slice %g', Opt.iSlc(i));
00127         title (stit);
00128         %axis ([0 szslc(1) 0 szslc(2)]);
00129 end
00130 
00131 err = 0;
00132 return;
00133 
 

Powered by Plone

This site conforms to the following standards: