Hi Ged,
many thanks for your email and instructions following
them I was able to read my idl data files into MATLAB
and visualize them. However when I use spm_write_vol I
get this error message which I can not figure out the
reason for:
>>???Index exceeds matrix dimensions.
Error in ==> /data2/datmp/spm2/spm_write_vol.m/
On line 22 ==> dt=V.dim(4); if dt>256, dt=dt/256; end;
Could you please comment?
Thank you,
--- Ged Ridgway <[log in to unmask]> wrote:
> Nas wrote:
> > I have saved some data as ".dat" in IDL
> (dimesnsion:
> > 128x128x8)and I would like to export them to
> Analyze
> > format. Does any of you have any tool for this
> that
> > could share with me please?
>
> Hi Nas,
>
> I'm not familiar with IDL, but if you can read the
> data into Matlab
> (I'll assume you're also a Matlab user, since you're
> posting to the
> SPM list!) then you could use spm_write_vol (from
> SPM2) to output an
> Analyze image (or the same from SPM5 for a NIfTI
> image).
>
> Look at the filesize in bytes, and calculate
> 128*128*8*(byte-depth of
> your data, e.g. 2 for int16, 4 for single/float32),
> if they match,
> great, it's probably stored raw, if not, guess that
> maybe there are
> some headers at the start, so you could try skipping
> this amount of
> bytes and seeing if the result makes sense... (bit
> dodgy, best to find
> out the specification of for the format of the .dat
> files.)
>
> Something along the lines of this (untested, and
> written in a hurry,
> so probably buggy/wrong, but hopefully...) should
> get you started:
>
>
%******************************************************************
> fid = fopen('file.dat');
> fseek(fid, SKIP, -1); % optional, where SKIP is
> number of bytes
> raw = fread(fid, inf, 'int16'); % change int16 if
> necessary
> fclose(fid);
> img = reshape(raw, [128 128 8]);
> % depending on storage order, may need to look into
> "permute" too
> V = struct('fname', 'file.img',...
> 'dim', [128 128 8],...
> 'dt', [spm_type('int16')
> spm_platform('BigEnd')],...
> 'mat', eye(4));
> % change matrix if world coords, origin etc. are
> important to you.
> spm_write_vol(V, img);
>
%******************************************************************
>
> Hope that helps,
> Ged.
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
|