> I just read the answer you sent and I'm not sure I understand what
> you're code does. What does it do more than if you use flipud in imaclac?
> As I always use flipped images I really wonder what this is all about!
The code does the same thing as using imcalc. It didn't take very long to
write, so I figured it may be useful for showing people how images can be
read into Matlab and then written out again. Here is a bit more explanation
of what goes on...
% Select the images to flip.
V=spm_vol(spm_get(Inf,'*.img'));
% Loop over each of the selected images
for i=1:length(V),
% VI is one specific image
VI = V(i);
% Generate an image based on the original
VO = VI;
% Break the filename down into its various parts
[pth,nm,xt,vr] = fileparts(deblank(VO.fname));
% Make a new filename for the output file, prefixed by "flipped_"
VO.fname = fullfile(pth,['flipped_' nm xt vr]);
% Modify the description field to say that the image has been flipped
VO.descrip = [VO.descrip ' - flipped'];
% Create the .hdr file, and maybe a .mat file
VO = spm_create_image(VO);
% Then loop through the planes of the current image
for j=1:VI.dim(3),
% Specify a plane to read in
M = spm_matrix([0 0 j]);
% Read in the jth plane.
% This section is the transverse slice at z = 0 after
% linear transformation according to matrix M
img = spm_slice_vol(VI,M,VI.dim(1:2),0);
% Flip the image
img = flipud(img);
% Write the out the flipped image to the new file
VO = spm_write_plane(VO,img,j);
end; % End of looping through planes
end; % End of looping through images
Best regards,
-John
--
Dr John Ashburner.
Wellcome Department of Cognitive Neurology.
12 Queen Square, London WC1N 3BG, UK.
tel: +44 (0)20 78337491 or +44 (0)20 78373611 x4381
fax: +44 (0)20 78131420
http://www.fil.ion.ucl.ac.uk/~john
mail: [log in to unmask]
|