SpmGraphics - MRC CBU Imaging Wiki
location: SpmGraphics

Working with graphics from SPM

Viewing SPM graphical output

Much of the output that SPM puts up in its graphics window (which is the large window on the right when SPM is running), it also saves into a postscript file, by default. To change the printing defaults, click on the the SPM defaults button, and choose Printing Options. In general, if the output is displayed automatically as part of what SPM is doing, then the output also goes to the file, whereas output that you request from SPM, for example using the statistical results button, does not get saved.If you want to save the output from a display that is not saved by default, then click on the "print" button at the top left of the graphics window.

In SPM the postscript output file is called "spm[something].ps"; where the [something] depends on your version of SPM (specifically spm.ps, spm99.ps, spm2.ps and spm_[date].ps` for versions 96, 99, 2 and 5 respectively). The file is saved in SPM's current working directory. Each new page is appended to any existing file of the same name. If your default printer in Unix is a postscript printer (it usually is), then you can print this file from the Unix prompt to your default printer using the command:

lpr spm.ps

where "spm.ps" is the name of the postscript file you wish to print. To view the file, use a postscript viewing utility. On Unix, you could try kghostview (on the CBU systems), or just ghostview, often available with the command gv. Suns have a pageview utility that does soemthing similar. You can also open postscript files in Linux programs like gimp. If you don't have kghostview or ghostview installed, please see the online reading page for more information.

Exporting SPM coordinates / p values as text to the matlab window

It is sometimes useful to get the coordinates etc table from the SPM results window into a text file. Do do this you may want to paste the table figures as text. In SPM, you can right click on some blank space in the table in the results window and choose Print text table from the menu that results. This causes the table to be output as text into the matlab window. You can then copy the text and paste it into your favourite text editor.

Editing SPM graphical output

It can be rather difficult to edit postscript file graphical output. You can edit the SPM output in the SPM graphics window to some extent. Use the buttons at the top of the graphics window to cut, move, and resize elements in the window, or add text comments. If you want the page you have modified to appear in the SPM postscript results file, then you will need to click on the Print or SPM-Print button in the top left hand corner of the graphics window. Editing SPM postscript files, or getting SPM graphics into other applications, can be rather easy, or rather difficult. There are three basic approaches:

  • Most basic of all: open the postscript file as text in a text editor, such as emacs, vi, or wordpad in Windows. Hence you can edit text labels etc. This is about as far from WYSIWYG as it gets.
  • Get the SPM output into bitmap format, and edit this. This is relatively easy, on both Unix and Windows, but the bitmap format means some loss of quality when editing or rescaling graphics or text.
  • Output SPM graphics in vectorized format for editing. This can be surprisingly difficult, but often gives much better results when images or text are significantly edited.
  • Hack SPM to write the output direct to a graphics file at maximum resolution. This works for example in providing high quality images of SPM maximum intensity projections (glass brain views).

Output SPM graphics into bitmap format

There are three options here. The first is to do a screen snapshot of SPM output you can see in the SPM figure window. On the Linux machines use the import command (which is from the ImageMagick package). See man import for the options. An example would be:

import -pause 5 my_image.tif

On a Sun you can use the Sun "snapshot" utility. Run from a Unix shell with "snapshot", select Region as snapshot target, and select the graphic you want. You can use the View button to view in the Sun imagetool, and, from imagetool, you can save to various formats which can be used with other programs, such as tiff.

On the PC, you could use a screen snapshot utility - have a look inhttp://www.freewarehome.com.

The second option is to print the SPM graphics direct to a bitmapped data format, such as tiff. You could do this by getting the relevant graphic up in the SPM graphics window, making sure the SPM graphics window is the current matlab figure window (by clicking inside the graphics window), and then print to a tiff file with a command like print -dtiff -noui myfigure.tif in the matlab command window. You can then import / edit the output in virtually any graphics program. You can also change the SPM printing defaults to print each page of the SPM output to a different tiff (or similar) file - see the SPM defaults Printing Options menus.

A third option is to import the SPM postscript file into a bitmap graphics editor directly. You can load SPM postscript files directly into the GIMP - for Windows or Unix. You may want to save individual pages of the .ps file (for example from within ghostview, using the Extract... option on the File Menu), to save importing many unnecessary pages. You will need to do this to load graphics into packages such as the Sun imagetool or the xv graphics package.

Graphics format problems in Windows

On Windows you have an extra problem, which is that some graphics packages, including versions of Adobe Photoshop and Illustrator, cannot interpret matlab postscript 2 format files, which are the default output from SPM. I last checked this a long time ago - so it is worth checking with whatever version you have to see if this is still a problem. If it is, consider trying the solution below.

There are two options. The first is to convert the SPM postscript output to Portable Document Format (PDF). This has the added advantage that you can print more than one page into the same PDF file, and load the pages individaully from within Photoshop, or Illustrator. The best way to convert the file is using Adobe Acrobat/Distiller. If you don't have this excellent program, you can use the postscript to pdf converter (ps2pdf) that is part of the Ghostscript distribution. You might need to do a little setup for this utility - particularly for Windows. It also produces some strange effects on our machines - with overthick lines on graphs and bounding boxes.

An alternative to conversion to PDF is to print to postscript level 1 format, which the Adobe applications can read. Postscript 1 gives rather larger output files than the default postscript 2, and this can be significant for a multipage SPM output file. To set to postscript 1 output, click on the SPM Defaults button, choose Printing Options, type in or accept a new file name for the .ps file, and then choose Postscript color as the output format. Alternatively you can print individual SPM output pages with a matlab command like "print -dpsc -painters -noui myfigure.ps". Make sure the SPM graphics window is the current figure at the time you run the command. If you have more than one page in the .ps file, you will need to save individual pages for editing using Ghostview, before loading into Photoshop or Illustrator

Output SPM graphics in vector format

Vectorized graphics usually give higher quality output, especially after editing or rescaling. However, it is not easy to get working. After much experimentation, this was the formula I resorted to. If you know a better one, please let me know.For output from the SPM graphics window, you will first need to get the output into a file that can be read by Adobe Illustrator, and second: pick out the bits of the figure that you want using Illustrator, and cut+paste.

Illustrator can understand PDF format, or matlab postscript 1 format - see above.

Next you can open the PDF or single page postscript file in Adobe Illustrator. In Illustrator, you should be able to select individual graphics elements within the page for copying etc, by using the Direct Selection Tool (white arrow). Select the graphic, then copy it to the clipboard with Ctrl-C or the copy command from the Edit menu. You can now paste direct into Word, for example. However, for some reason, pasting directly into Powerpoint doesn't work very well, at least for the Windows NT Office 97 version I was using at the time. Joe Hopfinger mailed to tell me that this was not a problem with his system, which included Office 2000. If you do have problems editing etc images pasted direct into Powerpoint, you can paste into Word first, do any cropping etc you may need, then copy the graphics within Word, and paste into Powerpoint. Even then, the graphic may look odd at certain scalings within Powerpoint. Ah well.

Other options I have tried, didn't work on my system. Windows meta files are also meant to be vectorized, but I couldn't get them to be editable with any utility I had to hand. However, Tom Nichols tells me that meta files work for him - perhaps this is an Office 97 / Office 2000 difference. To print to meta files in Windows, you can use the matlab command line (caveats as above) print -dmeta -painters -noui mypic.wmf. Adobe Illustrator format (print -dill ...) did not output the graphics properly. Postscript 2 format would not import into Illustrator.

Editing SPM to write graphics output directly

Tom Nichols pointed out this trick a few years ago. He put a small snippet of code at the end of the distribution version of the SPM96 glass brain graphic routine so that the routine could be asked to output high quality glass brain graphics to an image file, as well as to the SPM results window. See the end of the spm96 version of http://imaging.mrc-cbu.cam.ac.uk/scripts/spm_mip.m, after the three lines containing only a % sign. The same procedure can be used in later versions of SPM by copying the code fragment to end of spm_mip.m in SPM, and adding the following line above the fragment:

global XVIEWER TWD

Thence, to use the feature, you run SPM, and then type in the matlab window:

>> global XVIEWER
>> XVIEWER='xv'

where xv is the name of a graphics viewer you have on your system path. After you have done this, all MIPs (glass brains) that are shown in the SPM results windows are also displayed by the graphics viewer in high resolution, from whence they can be saved as GIF, TIFF etc.

Matthew Brett 15/5/00

CbuImaging: SpmGraphics (last edited 2013-03-07 21:23:01 by localhost)