Hi
I can confirm that this is a bug in the write_hdr_raw.m file located in the
folder @nifti/private in the spm5 directory. The problem only arises when
spm tries to write to a file's header without writing out a whole new image
file (i.e., in the case of reorienting files). Unfortunately it trashes the
image data in the process so you will have to recreate the files.
The spm_authors are aware of the bug and will hopefully post an official fix
soon.
Until then I suggest reverting to the previous version of write_header_raw.m
which I have attached to this email. Save the file as write_hdr_raw.m and
put it in the directory noted above. (Make sure to backup the file you are
replacing). This fix is only necessary if you have updated spm in the last
week or so.
Darren
----------
Darren Gitelman, MD
Department of Neurology
Northwestern University
voice: (312) 908-8614
fax: (312) 908-5073
page: (312) 695-1849
email: [log in to unmask]
----------
> -----Original Message-----
> From: SPM (Statistical Parametric Mapping)
> [mailto:[log in to unmask]] On Behalf Of Torben Ellegaard Lund
> Sent: Wednesday, January 02, 2008 9:30 AM
> To: [log in to unmask]
> Subject: Re: [SPM] Reorienting nii images problem with the
> latest Update 1048
>
> Dear All
>
> I can reproduce the error Kiyotaka reports. One of my
> structural images changed from 19,3MB to 4KB after applying
> and saving a rotation of .25 radians around the x-axis. This
> error was reproduced running
> SPM5 using matlab 7.4.0.287 (R2007a) on MacBook Pro running
> OS X version 10.5.1
>
>
> Best
> Torben
>
>
> Torben Ellegaard Lund
> Assistant Professor, PhD
> The Danish National Research Foundation's Center for
> Functionally Integrative Neuroscience (CFIN) Aarhus
> University Aarhus University Hospital Building 30
> Noerrebrogade 8000 Aarhus C Denmark
> Phone: +4589494380
> Fax: +4589494400
> http://www.cfin.au.dk
> [log in to unmask]
>
>
> These were the error messages i got:
>
> >> --------------------------
> Running "Display Image"
> Image "/Users/torbenl/Desktop/sRune-0002-00001-000001-01.nii"
> can not be resampled
>
> and after clicking in the image:
>
> >> Image
> "/Users/torbenl/Desktop/sRune-0002-00001-000001-01.nii" can
> not be resampled ??? Cant open image file.
>
> Error in ==> spm_image at 106
>
> set
> (st
> .in
> ,'String
> ',sprintf('%g',spm_sample_vol(st.vols{1},pos(1),pos(2),pos(3),
> st.hld)));
>
> Error in ==> spm_orthviews at 258
> eval(st.callback);
>
> ??? Error using ==> if
> strcmp
> (get(gcf,'SelectionType'),'normal'),spm_orthviews('Reposition');elseif
> strcmp
> (get
> (gcf
> ,'SelectionType
> '),'extend
> '),spm_orthviews('reposition');spm_orthviews('context_menu','t
> s',1);end;
> Cant open image file.
>
> ??? Error while evaluating axes ButtonDownFcn
>
>
>
>
>
>
>
>
>
>
>
> On 02/01/2008, at 15.41, Volkmar Glauche wrote:
>
> > Dear Kiyotaka Nemoto,
> >
> > I can't confirm this with the latest SPM5 version here. If
> it is not
> > SPM, the failure you observe could be due to file system
> problems (out
> > of disk space, permissions, file locking by another application).
> >
> > Volkmar
> >
> > On Wed, 2008-01-02 at 22:54 +0900, Kiyotaka Nemoto wrote:
> >> Dear SPM developers,
> >>
> >> I came across with a problem when I try to reorient .nii
> images via
> >> display button with the latest Update 1048. I think this may be a
> >> bug, so I report the problem.
> >>
> >> Below is what I did.
> >>
> >> 1) Dicom files were converted to an Nifti image with
> Jolinda Smmith's
> >> MRIConvert. Files are stored as a single nii file.
> >>
> >> 2) An nii image was displayed with "Display" function.
> SPM5 displays
> >> the image without any problems.
> >>
> >> 3) I set AC-PC manually and push "Reorient images...", reorienting
> >> the image.
> >>
> >> 4) Then I get into trouble. The graphics window went white
> only with
> >> a frame and an error message in Matlab says, "Image cannot be
> >> resampled..." "file too small"
> >>
> >> 5) I checked the file size and saw that now the nii file I
> tried to
> >> reorient is only 348 bytes, which is the same as usual .hdr files.
> >> That is, nii file with a header and an image (over 20Mbytes) was
> >> replaced with a mere header information and image itself
> was lost...
> >> So, this must have something to do with handling header
> information
> >> of nii format.
> >>
> >> I checked the following to make sure that this is a problem of
> >> handling nii format and this doesn't happen with previous versions;
> >>
> >> A) I prepared Analyze format images (.hdr and .img files) and went
> >> through the same procedure I described above. This time everything
> >> works fine.
> >>
> >> B) I re-installed SPM5 in a different directory, and applied Update
> >> 958 (the last update). This also worked fine. Nii files
> were handled
> >> correctly.
> >>
> >> Below is my computer environment, (though I think it is not so
> >> important since Update958 works fine with this environment...)
> >>
> >> CPU: Athlon64 3800+
> >> OS: openSUSE 10.3 64bit
> >> Matlab: R2007b 7.5.0.338 (64bit)
> >> gcc: 4.2.1
> >>
> >>
> >> Any advice or proposal would be appreciated.
> >>
> >> Best regards and wish you a happy new year!
> >>
> >> Kiyotaka
> >>
> >>
> > --
> > Volkmar Glauche
> >
> > Freiburg Brain Imaging
> > http://fbi.uniklinik-freiburg.de/
> > Phone +49(0)761 270-5331
> > Fax +49(0)761 270-5416
>
function ok = write_hdr_raw(fname,hdr,be)
% Write a NIFTI-1 .hdr file.
% FORMAT ok = write_hdr_raw(fname,hdr,be)
% fname - filename of image
% hdr - a structure containing hdr info
% be - whether big-endian or not
% ok - status (1=good, 0=bad)
% _______________________________________________________________________
% Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
%
% $Id: write_hdr_raw.m 1029 2007-12-19 18:30:38Z john $
[pth,nam,ext] = fileparts(fname);
if isfield(hdr,'magic')
org = niftistruc;
switch deblank(hdr.magic)
case {'ni1'}
hname = fullfile(pth,[nam '.hdr']);
case {'n+1'}
hname = fullfile(pth,[nam '.nii']);
otherwise
error('Bad header.');
end;
else
org = mayostruc;
hname = fullfile(pth,[nam '.hdr']);
end;
if nargin >=3
if be, mach = 'ieee-be';
else mach = 'ieee-le';
end;
else mach = 'native';
end;
ok = true;
fp = fopen(hname,'r+',mach);
if fp==-1
fp = fopen(hname,'w+',mach);
if fp==-1
ok = false;
return;
end;
end;
for i=1:length(org)
if isfield(hdr,org(i).label),
dat = hdr.(org(i).label);
if length(dat) ~= org(i).len,
if length(dat)< org(i).len,
dat = [dat(:) ; zeros(org(i).len-length(dat),1)];
else
dat = dat(1:org(i).len);
end;
end;
else
dat = org(i).def;
end;
% fprintf('%s=\n',org(i).label)
% disp(dat)
len = fwrite(fp,dat,org(i).dtype.prec);
if len ~= org(i).len,
ok = false;
end;
end;
fclose(fp);
if ~ok,
fprintf('There was a problem writing to the header of\n');
fprintf('"%s"\n', fname);
end;
return;
|