help
help > RE: How to open image + overlay with terminal command (Mac OS)
Dec 28, 2018 08:12 PM | Chris Rorden
RE: How to open image + overlay with terminal command (Mac OS)
I am afraid that MRIcron is not very good with command line
scripts. Particularly on MacOS. Furthermore, be aware that when you
run system commands from Matlab you may not get all your user
environment variables loaded, which makes scripting other programs
with Matlab a little bit more challenging.
I would encourage you to upgrade to try MRIcroGL v1.2.20181114 if you are interested in scripting.
function runGL(bg, overlay)
%launch MRIcroGL and display an image
% bg: name of background image to load
% overlay: name of overlay image
glExe = '/Users/rorden/MRIcroGL12/MRIcroGL.app/Contents/MacOS/MRIcroGL';
if ~exist(glExe,'file'), error('Unable to find %s', glExe); end
if ~exist('bg','var'), bg = 'spm152'; end
if ~exist('overlay','var'), overlay = 'spmMotor'; end
%create script
fnm = fullfile(fileparts(mfilename),'script.py');
fileID = fopen(fnm,'w');
fprintf(fileID, 'import gl\n');
fprintf(fileID, 'gl.resetdefaults()\n');
fprintf(fileID, sprintf('gl.loadimage("%s")\n', bg));
fprintf(fileID, sprintf('gl.overlayload("%s")\n', overlay));
fclose(fileID);
%run script
cmd = [glExe,' "', fnm ,'" &']
system(cmd);
I would encourage you to upgrade to try MRIcroGL v1.2.20181114 if you are interested in scripting.
- As noted on the home page, MacOS hides graphical applications as packages. This means that a command line script will look like this "/Users/rorden/MRIcroGL12/MRIcroGL.app/Contents/MacOS/MRIcroGL spm152 spmMotor -cm actc -dr 2 4". I tend to run the command "nano ~/.bash_profile" and add the line an alias that points to the application: "alias mricrogl='/Users/rorden/MRIcroGL12/MRIcroGL.app/Contents/MacOS/MRIcroGL'", with this in your profile, you can run shorter commands "mricrogl spm152 spmMotor -cm actc -dr 2 4" (just be aware that Matlab may ignore any settings in your bash_profile).
- As shown in the comment above (and the home page), MRIcroGL 1.2 uses a lot of the same command line options as fsleyes. That way you can pick and choose the right tool for the task at hand.
- MRIcroGL includes a full scripting language. Assuming you have v1.2, click on the Scripting/Templates menu to see a few samples to get you started. The core functions are described here.
- The MRIcroGL Wiki and Surfice wiki both describe how to execute scripts from Matlab, Python or any other language that lets you launch external programs.
function runGL(bg, overlay)
%launch MRIcroGL and display an image
% bg: name of background image to load
% overlay: name of overlay image
glExe = '/Users/rorden/MRIcroGL12/MRIcroGL.app/Contents/MacOS/MRIcroGL';
if ~exist(glExe,'file'), error('Unable to find %s', glExe); end
if ~exist('bg','var'), bg = 'spm152'; end
if ~exist('overlay','var'), overlay = 'spmMotor'; end
%create script
fnm = fullfile(fileparts(mfilename),'script.py');
fileID = fopen(fnm,'w');
fprintf(fileID, 'import gl\n');
fprintf(fileID, 'gl.resetdefaults()\n');
fprintf(fileID, sprintf('gl.loadimage("%s")\n', bg));
fprintf(fileID, sprintf('gl.overlayload("%s")\n', overlay));
fclose(fileID);
%run script
cmd = [glExe,' "', fnm ,'" &']
system(cmd);
Threaded View
Title | Author | Date |
---|---|---|
sjack | Dec 28, 2018 | |
Chris Rorden | Dec 28, 2018 | |