Example Mesh Snapshot Script

From VISTA LAB WIKI

Jump to: navigation, search

This page contains the text for an example MATLAB script which takes snapshots of many gray matter surface Meshes across subjects, saving a separate .png image file for each subject, hemisphere, data map, and view angle. It calls some other lookup functions which are omitted to anonymize the data. The key code is in the main loop, which calls the meshRetrieveSettings function to iteratively retrieve different view settings, then uses mrmGet to grab a snapshot of the mesh image.



[edit] Main script code

% script prfMeshImages:

%

% collects a bunch of mesh images automagically in each pRF session, saves them

% in the 'Images/' folder of each session, and creates a power point file based

% on the images.

%

%

% ras, 080908.


%% params

sessions = prf_sessions;

rois = {'aFus_faces_2mm' 'pFus_faces_2mm' 'PPA_2mm' ...

'V1' 'V2v' 'V3v' 'V4' 'VO1'};  % 'FBA_2mm'


dtNames = {'Averages' 'CheckerboardAverages' 'HouseAverages' 'FaceAverages' ...

'FaceOdd' 'FaceEven' }; % 'Odd' 'Even' 'HouseOdd' 'HouseEven' 'CheckerboardOdd' 'CheckerboardEven'

meshViews = { {'VentralZoom' 'Medial' 'LateralOccipital'} ...

{'VentralZoom' 'Medial' 'LateralOccipital'} };

fields = {'co' 'map' 'ph' 'amp'};

fieldNames = {'Variance Explained' 'Log Eccentricity' 'Polar Angle' 'pRF Diameter'};

lr = 'LR'; leftright = {'Left' 'Right'}; rightleft = {'right' 'left'};


%%%%% MAIN LOOP: Across Sessions

for s = 1:length(sessions)

cd( fullfile(prfDir, sessions{s}) );

meshes = prf_meshFiles(pwd);


ensureDirExists('Images');


%% open the view

mrvCleanWorkspace;

mrVista 3

VOLUME{1} = prfLoadROIs(VOLUME{1}, rois);

VOLUME{1}.ui.showROIs = -2; % show all

VOLUME{1} = refreshScreen(VOLUME{1});

for h = 1:2

meshPath = fullfile('3DAnatomy', leftright{h}, '3DMeshes', meshes{h});

VOLUME{1} = meshLoad(VOLUME{1}, meshPath, 1);

end


%% loop across data types, pRF models

for dt = dtNames

VOLUME{1} = selectDataType(VOLUME{1}, dt{1});


%% load the model / maps

VOLUME{1} = prfLoadModel(VOLUME{1});


%% loop across view fields

for f = 1:length(fields)

VOLUME{1} = setDisplayMode(VOLUME{1}, fields{f});


% set viewing parameters appropriate to the field

if isequal(fields{f}, 'co')

VOLUME{1} = setCothresh(VOLUME{1}, 0.15); % minimal thresholding

VOLUME{1}.ui.coMode.clipMode = [0 .6];

else

VOLUME{1} = setCothresh(VOLUME{1}, 0.15);

VOLUME{1}.ui.coMode.clipMode = [0 .6];

end


%% loop across meshes (hemispheres)

for h = 1:2

if isequal(fields{f}, 'ph')

% VOLUME{1}.ui.phMode.cmap(129:end,:) = circshift(hsv(128), 32);

VOLUME{1} = cmapPolarAngleRGB(VOLUME{1}, rightleft{h});

else

VOLUME{1} = setPhWindow(VOLUME{1}, [0 2*pi]);

end

VOLUME{1}.meshNum3d = h;

meshColorOverlay(VOLUME{1});


%% loop across mesh view settings

for j = 1:3

meshRetrieveSettings(VOLUME{1}.mesh{h}, meshViews{h}{j});


img = mrmGet(VOLUME{1}.mesh{h}, 'screenshot') ./ 255;

saveName = sprintf('%s %sH %s %s.png', meshViews{h}{j}, ...

lr(h), fieldNames{f}, dt{1});

savePath = fullfile(pwd, 'Images', saveName);

imwrite(img, savePath, 'png');

fprintf('Saved %s.\n', savePath);

end

end

end

end


%% close the volume view / meshes

VOLUME{1} = meshDelete(VOLUME{1}, Inf);

figure(VOLUME{1}.ui.figNum);

closeVolumeWindow;


%% make the PowerPoint file

prfMakePPTFromImages;

end

return


[edit] Pasting Images into PowerPoint

The above code also calls a second function which pastes the saved images into a PowerPoint deck for easy viewing. Here is the code for that function:

function [pptPath status] = prfMakePPTFromImages(sessDir, dtNames);

% Using images created from the meshscript_[date] script for each object

% pRF session, create a power point deck with images from both hemispheres,

% for easy comparison.

%

% [pptPath status] = prfMakePPTFromImages([sessDir=pwd], [dtNames]);

%

% ras, 08/2008.

if notDefined('sessDir'), sessDir = pwd; end

if notDefined('dtNames'),

dtNames = {'Averages' 'FaceAverages' 'HouseAverages' 'CheckerboardAverages'};


% alternate: include odd/even subsets

% dtNames = {'Averages' 'FaceAverages' 'HouseAverages' 'CheckerboardAverages' ...

% 'Odd' 'Even' 'FaceOdd' 'FaceEven' 'HouseOdd' 'HouseEven' ...

% 'CheckerboardOdd' 'ChecerkboardEven'};

end


%% get params

cd(sessDir);

load mrSESSION

sessName = mrSESSION.sessionCode;

fields = {'Variance Explained' 'Log Eccentricity' 'Polar Angle' 'pRF Diameter'};

viewAngles = {'Medial' 'LateralOccipital' 'VentralZoom'};

hemiOrder = {[2 1] [1 2] [2 1]}; % L=1, R=2: order on the slide


%% open the PPT file

pptFile = sprintf('pRF Mesh Images %s.ppt', sessName);

pptPath = fullfile(prfDir, 'results', pptFile);

[ppt op] = pptOpen(pptPath);


%% main loop

for v = viewAngles

% make a title slide for this analysis

hFig = figure('Color', 'w');

axes; axis off;

pptPaste(op, hFig, 'meta', v{1});

close(hFig);


for f = fields

for dt = dtNames

% load the images

lh = imread( sprintf('Images/%s LH %s %s.png', v{1}, f{1}, dt{1}) );

rh = imread( sprintf('Images/%s RH %s %s.png', v{1}, f{1}, dt{1}) );


% display in a figure

hFig = figure('Color', 'w', 'Units', 'norm', 'Position', [.1 .1 .8 .8]);

hAx(1) = subplot('Position', [0 0 .5 1]);

hAx(2) = subplot('Position', [.5 0 .5 1]);


if isequal( hemiOrder{cellfind(viewAngles, v{1})}, [1 2] );

% display left, then right

axes(hAx(1)); imagesc(lh); axis image; axis off; title('LH')

axes(hAx(2)); imagesc(rh); axis image; axis off; title('RH')

else

% display right, then left

axes(hAx(1)); imagesc(rh); axis image; axis off; title('RH')

axes(hAx(2)); imagesc(lh); axis image; axis off; title('LH')

end


% add a colorbar

switch f{1}

case 'Variance Explained',

cmap = mrvColorMaps('blueredyellow', 256);

% cmap = hot(256);

clim = [0 .6];

colorWheel = 0;

case 'Eccentricity',

cmap = mrvColorMaps('hsvshort', 256);

% clim = [0 30];

colorWheel = 0;

case 'Log Eccentricity',

cmap = mrvColorMaps('hsvshort', 256);

clim = [0 1.3];

colorWheel = 0;

case 'Polar Angle',

cmap = mrvColorMaps('rgb', 128);

cmap = [cmap; flipud(cmap)];

clim = [0 360];

colorWheel = 1;

case 'pRF Diameter',

cmap = flipud( mrvColorMaps('hsvshort', 256) );

% cmap = jet(256);

clim = [0 15];

colorWheel = 0;

end

cbar = cbarCreate(cmap, f{1}, 'Clim', clim, ...

'ColorWheel', colorWheel, ...

'ColorWheelStart', 180);

hLeg = mrvPanel('below', .15);

axes('Parent', hLeg, 'Units', 'norm', 'Position', [.3 .3 .4 .4]);

cbarDraw(cbar, gca);


% copy into PPT

ttl = sprintf('%s %s', dt{1}, f{1});

pptPaste(op, hFig, 'meta', ttl);


% close figure

close(hFig);

end

end

end


pptClose(op, ppt, pptPath);


fprintf('\n\n\t*** [%s]: All done! ***\n\n', mfilename);


return


Personal tools