Bruce Fischl wrote:

(2) Import that surface onto Matlab and visualize it there.


There is such a visualizer in the 'dev' tree of FreeSurfer -- called 'mris_display'. I've appended the relevant m files -- just save to a dir on your MatLAB path.

-=R

--
Rudolph Pienaar, M.Eng, D.Eng / email: rudo...@nmr.mgh.harvard.edu
MGH/MIT/HMS Athinoula A. Martinos Center for Biomedical Imaging
149 (2301) 13th Street, Charlestown, MA 02129 USA
function [] = colprintf(aC, astr_LC, varargin)
%
% NAME
%
%  function [] = colprintf(aC, astr_LC, format, ...)
%  $Id: colprintf.m,v 1.2 2010/02/01 20:52:10 rudolph Exp $
%
% ARGUMENTS
% INPUT
%       aC              class/col width         if class - queried for col
%                                               widths, else parsed for 
%                                               width spec
%       astr_LC         string                  Left-column 'intro' text
%       format, ...     string                  C-style format string to print
%                                               in right column.
%
% OPTIONAL
%
% DESCRIPTION
%
%       Prints two-tuple text inputs in two-columns, with column widths
%       defined in the hosting class <aC> or alternatively if aC is a 
%       string of form "<LC>;<RC>"
%       
%       A carriage-return is appended to the end of the right string
%       col.
%
% NOTE:
%
% HISTORY
% 18 September 2009
% o Initial design and coding.
%

        LC              = 40;
        RC              = 40;
        verbosity       = 1;

        if isobject(aC)
            LC          = aC.m_LC;
            RC          = aC.m_RC;
            verbosity   = aC.m_verbosity;
        else
            [str_LC, str_RC]    = strtok(aC, ';');
            LC                  = str2num(str_LC);
            RC                  = str2num(str_RC);
        end

        sfrmt   = sprintf(varargin{:});

        if length(astr_LC) & verbosity
            fprintf(1, '%s', sprintf('%*s',   LC, astr_LC));
        end
        if length(sfrmt)   & verbosity
            fprintf(1, '%s', sprintf('%*s\n', RC, sfrmt));
        end
end
function [hf, hp, av_filtered] = mris_display(astr_mris, astr_curv, varargin)
%
% NAME
%       [hf, hp, av_filtered]   =                       ...
%       mris_display(           astr_mris,              ... 
%                               astr_curv               ...
%                               <, a_az,                ... 
%                               a_el,                   ...
%                               af_bandFilter,          ...
%                               ab_invMap>
%                         )
% $Id: mris_display.m,v 1.2 2010/02/01 20:52:10 rudolph Exp $
%
%
% ARGUMENTS
%       
%       INPUT
%       astr_mris       string          filename of surface file to load
%       astr_curv       string          filename of curvature file to load
%
%       OPTIONAL
%       a_az            float           azimuth of viewpoint
%       a_el            float           elevation of viewpoint
%       af_bandFilter   float           apply a symmetrical band pass filt
%                                       between +- <af_bandFilter>
%       ab_invMap       bool            if true, invert the sign of the
%                                       curvature data -- useful if 'neg'
%                                       values are on gyri and 'pos' values
%                                       in sulci.
%
%       OUTPUT
%       hf              handle          handle to generated figure
%       hp              handle          handle to patch
%       av_filtered     vector          number of vertices in original curv
%                                       that have been filtered out by the
%                                       <af_bandFilter>.
%
% DESCRIPTION
%
%       'mris_display' reads a FreeSurfer surface structure and
%       displays it as seen from an optional <a_az, a_el>.
%
%       The <av_curv> can be further band pass filtered by passing
%       an <af_bandFilter> parameter, in which case the curvature
%       vector is hardlimited to [-<af_bandFilter>, ... <af_bandFilter>].
%
% PRECONDITIONS
%       o <astr_mris> and <astr_curv> should be valid filenamesi.
%       o FreeSurfer environment.
%
% POSTCONDITIONS
%       o Figure is generated.
%       o handle to figure is returned.
%
% HISTORY
% 26 August 2009
% o Initial design and coding.
%

% ---------------------------------------------------------

%%%%%%%%%%%%%% 
%%% Nested functions :START
%%%%%%%%%%%%%% 
        function error_exit(    str_action, str_msg, str_ret)
                fprintf(1, '\tFATAL:\n');
                fprintf(1, '\tSorry, some error has occurred.\n');
                fprintf(1, '\tWhile %s,\n', str_action);
                fprintf(1, '\t%s\n', str_msg);
                error(str_ret);
        end

        function vprintf(level, str_msg)
            if verbosity >= level
                fprintf(1, str_msg);
            end
        end

%%%%%%%%%%%%%% 
%%% Nested functions :END
%%%%%%%%%%%%%% 


sys_printf('mris_display: START\n');
 
az              = 270;
el              = 0;

b_bandFilter    = 0;
af_bandFilter   = 1;
b_invCurv       = 0;

% Parse optional arguments
if length(varargin) >= 1, az = varargin{1};             end
if length(varargin) >= 2, el = varargin{2};             end
if length(varargin) >= 3
    b_bandFilter        = 1;
    af_bandFilter       = varargin{3};
end
if length(varargin) >= 4, b_invCurv = varargin{4};      end

% Read curvature file
cprintsn('Reading curvature file', astr_curv);
[v_curv, fnum] = read_curv(astr_curv);
cprintdn('Number of curv elements', numel(v_curv));
if b_invCurv
    cprintdn('Invert curvature data sign', b_invCurv);
    v_curv = v_curv * -1;
end

% Read surface
colprintf('40;40', 'Reading mris file', astr_mris);
[v_vertices, v_faces] = read_surf(astr_mris);
v_vertSize      = size(v_vertices);
v_faceSize      = size(v_faces);
str_vertSize    = sprintf('%d x %d', v_vertSize(1), v_vertSize(2));
str_faceSize    = sprintf('%d x %d', v_faceSize(1), v_faceSize(2));
colprintf('40;40', 'Size of vert struct', str_vertSize);
colprintf('40;40', 'Size of face struct', str_faceSize);

if numel(v_curv) ~= v_vertSize(1)
    error_exit( 'reading inputs',        ...
                'mismatch between curvature size and surf vertices', ...
                '1');
end

v_vertices      = single(v_vertices);
v_faces         = int32(v_faces+1);  % for matlab compliance

av_filtered     = [0 0];
if b_bandFilter
    lowerCount  = numel(find(v_curv<-af_bandFilter));
    upperCount  = numel(find(v_curv>af_bandFilter));
    av_filtered = [lowerCount upperCount];
    v_curv      = filter_bandPass(v_curv,                       ...
                                -af_bandFilter, af_bandFilter, 1);
end

% Display:
hf              = figure;
hp              = patch('vertices',     v_vertices,             ...
                        'faces',        v_faces(:,[1 3 2]),     ...
                        'facevertexcdata',      v_curv,         ...
                        'edgecolor',    'none',                 ...
                        'facecolor',    'interp'); 
axis equal; 
grid;
%colormap('winter');
demcmap(v_curv);
title(sprintf('%s: %s', astr_mris, astr_curv));
colorbar;
view(az, el);

sys_printf('mris_display: END\n');

end
% ---------------------------------------------------------


function [s] = sys_printf(varargin)
%
% NAME
%
%  function [s] = sys_printf(format, ...)
%  $Id: sys_printf.m,v 1.2 2010/02/01 20:52:10 rudolph Exp $
%
% ARGUMENTS
% INPUT
%       format, ...     string          C-style format string to print
% OPTIONAL
%       
% OUTPUT
%       s               string          syslog-style prefixed string
%
% DESCRIPTION
%
%       This function prepends <format> with syslog_prefix().
%
% PRECONDITIONS
%
% POSTCONDITIONS
%       o string is returned and printed.
%
% NOTE:
%
% HISTORY
% 12 December 2008
% o Initial design and coding.
%
sfrmt   = sprintf(varargin{:});
s       = sprintf('%s %s', syslog_prefix(), sfrmt);
fprintf(1, '%s', s);
function [s] = syslog_prefix(varargin)
%
% NAME
%
%  function [s] = syslog_prefix()
%  $Id: syslog_prefix.m,v 1.2 2010/02/01 20:52:10 rudolph Exp $
%
% ARGUMENTS
% INPUT
%
% OPTIONAL
%       
% OUTPUT
%       s       string          syslog-style prefix string
%
% DESCRIPTION
%
%       This function generates a syslog-style prefix string,
%       suitable for time stamping log-type messages
%
% PRECONDITIONS
%
%       o un*x runtime that understands the 'host' command
%
% POSTCONDITIONS
%
%       o s = "YYYY mmm dd hh:mm:ss <host>"
%
% NOTE:
%
% HISTORY
% 02 August 2007
% o Initial design and coding.
%

[str_ret str_hostname]  = system('hostname');
[str_host str_rem]      = strtok(str_hostname, char(10));

clk                     = fix(clock);
year                    = clk(1);
month                   = clk(2);
day                     = clk(3);
hour                    = clk(4);
minute                  = clk(5);
seconds                 = clk(6);

switch(month)
    case 1
        str_month       = 'Jan';
    case 2
        str_month       = 'Feb';
    case 3
        str_month       = 'Mar';
    case 4
        str_month       = 'Apr';
    case 5
        str_month       = 'May';
    case 6
        str_month       = 'Jun';
    case 7
        str_month       = 'Jul';
    case 8
        str_month       = 'Aug';
    case 9
        str_month       = 'Sep';
    case 10
        str_month       = 'Oct';
    case 11
        str_month       = 'Nov';
    case 12
        str_month       = 'Dec';
end

s = sprintf('%d %s %02d %02d:%02d:%02d %s', year, str_month,    ...
        day, hour, minute, seconds, str_host);
_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer

Reply via email to