Dear Meghana, dear Karl,
sometimes flipping of images without prior normalization is appropriate.
Indeed flipped normalized images are not normalized any more. Exactly
for this reason I rewrote Karls code. My version also writes flipped
images. But now the mat-files are properly adjusted for the flipped
image data. For interactive use start with "spm_flip".
I missed the mail from Meghana: Please forward this one.
The name of my snippet is "spm_flip.m", too. If it is renamed, the first
and third line should be changed accordingly:
function spm_flip(V)
% flips images, writes them and adjusts their mat-files
% FORMAT spm_flip
% V - a vector of structures containing image volume information.
% For explanation of the elements of the structure see spm_vol
%___________________________________________________________________________
%
% If spm_flip is called without argument, the interactive function
spm_get
% is used for getting images.
%
% The data of the images is flipped in voxel-x-direction.
% The new images are written to img-files with a leading "f".
% The associated new mat-files are calculated to obtain a flipping in
% world-x-direction (the left-right-direction, if the respective prior
image
% is aligned properly).
%___________________________________________________________________________
% Author: Thomas Kamer
% Last change: 2001/04/12
% Version: 1.0
% Dependencies: SPM99
%
% Usage of code from Karl Friston
%
% Distributed under GNU General Public License (GPL) as published by the
% Free Software Foundation (Version 2 or higher)
%
% Laboratory for Psychiatric Brain Research,
% Department for Psychiatry,
% University of Bonn
if nargin==0
% get image names
P = spm_get(Inf,'*.img',{'select images for flipping'});
% start progress bar
spm_progress_bar('Init',length(P),'flipping','');
% circle through images
for i = 1:length(P)
% flip and write
flip( spm_vol(P{i}) );
% show progress
spm_progress_bar('Set',i);
end
% end progress bar
spm_progress_bar('Clear')
else
% circle through images
for i = 1:length(V)
% flip and write
flip( V(i) );
end
end
function flip(Vi)
% flips image, calculates mat-data, writes all
% get image data
Y = spm_read_vols(Vi,0);
% flip image data
Y = flipdim(Y,1);
% prepare name and header of image
Vo = Vi;
[p,f,e,v] = fileparts(Vi.fname);
Vo.fname = fullfile(p,['f' f e]);
Vo.descrip = [Vo.descrip ' - flipped'];
% calculate adjusted mat-file data
Vo.mat(1:3,4) = Vo.mat(1:3,4)+Vo.mat(1:3,1)*Vo.dim(1);
Vo.mat(2:3,1) = -Vo.mat(2:3,1);
Vo.mat(1,2:4) = -Vo.mat(1,2:4);
% write flipped image
Vo = spm_write_vol(Vo,Y);
Best wishes,
Thomas Kamer
--
Thomas Kamer
Computer scientist
University of Bonn
Department for Psychiatry
Laboratory for Psychiatric Brain Research
Sigmund-Freud-Straße 25
D-53105 Bonn
Germany
Tel: +49-(0)228-287-6366
Fax: +49-(0)228-287-6369
[log in to unmask]
For verification of my signature see https://trust.web.de/root.htm
|