June 02, 2010

SPM99 Gem 17: Origin maddness

A source of confusion is where the origin (the [0,0,0] location of an image) is stored. When there is no associated .mat file, the origin is read from the Analyze originator field. If this is zero it is assumed to match the center of the image field of view. If thereisa .mat file, then the origin is the first three values of

        M\[0 0 0 1]'
                
whereMis the transformation matrix in the .mat file.

One limitation is that the origin stored in the Analyze header is a (short) integer, and so cannot represent an origin with fractional values. To set the origin to specific, fractional value, use this code snippet:

  Orig = [ x y z ]; % Desired origin in units of voxels
  P = spm_get(Inf,'*.img'); % matrix of file names

  for i=1:size(P,1)

    M = spm_get_space(deblank(P(i,:)));
    R = M(1:3,1:3);
    % Set origin
    M(1:3,4) = -R*Orig(:);
    spm_get_space(deblank(P(i,:)),M);
 	
  end


- No comments


Add a comment

Name
Email
Anti-Spam Question
My t-shirt is red. What colour is my t-shirt?
Anti-Spam Answer
Comment


Your IP address will be recorded. -

You can not use HTML, but you can use our special markup -

Search this blog

Tags

Most recent comments

  • Hi, Folks, conversion to HTML still works for PPT 2011 under OS 10.10 (as on my computer), with coup… by Andrew Fisher on this entry
  • HTML pages are different from PPT. It is possible to convert PPT in HTML page but it will create a p… by Ramjas on this entry
  • Hi This doesn't really address the issue at hand (powerpoint to html), but an alternative and very e… by Rose on this entry
  • @Michael. You are a SAINT. BLESS. by emma riley on this entry
  • I look this up every couple of years, and always struggle with it, so here are some notes for improv… by johann beda on this entry

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXIX