Print

Print


dear steven,

maybe i misunderstood what the real problem is for you. but if you just run out of memory, isn't it an option to convert smaller chunks at a time?

i realize you might not want to sit there all day converting thousands of files 50 at a time so try to modify the code below for your needs. it will call the dicom convert tool for files in smaller chunks so you won't run out of memory.

Chunk = 50 % number of files that fit in memory at a time

 Pin = spm_select(Inf, '*', 'Select DICOM files'); % select all the files you want to convert

 for i = 1:round(length(Pin)/Chunk)

        if i < round(length(Pin)/Chunk)
            Pchunk(vol,:) = Pin((i -1)*Chunk + 1:(i -1)*Chunk + 50,:)   % This will select Chunk number of files
        else
            Pchunk(vol,:) = Pin((i -1)*Chunk + 1:end,:)  % This will select the last bit of files that are less than Chunk at the end
        end % end 'if' statement

     [zir zame zext] = fileparts(Pchunk(1,:));
     eval(['cd ' mat2str(zir)]);
     hdr = spm_dicom_headers(Pchunk);
     spm_dicom_convert(hdr,'mosaic');

     end % end of for loop with 'vol'
 end % end of for loop with 'i'

it might have some bugs as i typed it in and didn't test it. but if you otherwise want to go for the idea just run into bugs with it feel free to drop me a line off the list.

i hope it helps,
zoltan



On 31 Mar 2009, at 15:31, Torben Ellegaard Lund wrote:

Dear Steven, John and others

I think the dicom converter in SPM does an excellent job, and when it comes to orientation I have seen nothing like it. I would actually argue that the people who are to blame are the ones who think that each slice needs its own DICOM file.

Best
Torben




Den 31/03/2009 kl. 15.17 skrev Steven Liu:

Dear John:

  I used SPM_DICOM_essential also in SPM8b, but it does not help.
The problem here is that when you try to convert too many fMRI DICOM files, for example,
if you have 300 volumes, each with 50 slices, you will have 15000 DICOM files
to convert into Analyze, then spm_dicom_convert will fail due to memory
problem.  Even if it does not fail,  it will take very very long time to complete
such a converting.   I think, this is a big bug since SPM2, SPM5 or SPM8b
has not resolved this problem.  SPM has to make a C+++ version for this function
or totally change the way of coding and processing in the next version of SPM.
At now, we can use the latest version of MRIConvert or MRICron (each of the two
software packages has a command-line exe file for you to run at a batch mode
without through a GUI)  to convert big fMRI DICOM files.
   But for a few number of DICOM files, spm_dicom_convert works excellently
becasue it takes care the origin much more accurately than any other software.

Steven

Steven




On Tue, Mar 31, 2009 at 7:35 AM, John Ashburner <[log in to unmask]> wrote:
The memory problems were occuring because all the header info was stored from
all the DICOM files, so that it could be sorted into different volumes.  A
more recent version of the converter only saves the essential fields in
memory.  This is available in SPM8b, but also may (not entirely sure) be
included among the recent updates for SPM5.

Best regards,
-John

On Tuesday 31 March 2009 03:52, Michael T Rubens wrote:
> try dicominfo instead of spm_dicom_headers (I think you need Image
> Processing Toolbox).
> Michael
>
> 2009/3/30 Steven Liu <[log in to unmask]>
>
> > I used to have the same problem when I converted more than 280 volumes,
> > each of
> > which had more than 40 slices. And it is very slow to use
> > SPM_DICOM_Convert to
> > convert fMRI DICOM files to Analyze. It is ok if you use it to convert a
> > few number of DICOM
> > files, such as Structural DICOM files.  You may use MRIConvert to convert
> > functional
> > DICOM when you have too many files.
> >
> >
> > Steven
> >
> >
> >
> > 2009/3/30 ±«Ãô <[log in to unmask]>
> >
> > Hi,
> >
> >> Excuse me for a beginner's question. I am trying to convert the original
> >>  dicom files to the format that can be recognized by SPM5. So I tried
> >> using
> >>  spm_dicom_convert and spm_dicom_headers. However, the following error
> >>
> >> messages appeared:
> >> >> spm_dicom_headers('003_0001');
> >>
> >> ??? Error using ==> fread
> >> Out of memory. Type HELP MEMORY for your options.
> >>
> >> Error in ==> spm_dicom_headers>decode_csa2 at 508
> >>        t(i).item(j).val = fread(fp,len,'*char')';
> >>
> >> Error in ==> spm_dicom_headers>decode_csa at 425
> >>    t = decode_csa2(fp,lim);
> >>
> >> Error in ==> spm_dicom_headers>read_dicom at 100
> >>                dat  = decode_csa(fp,tag.length);
> >>
> >> Error in ==> spm_dicom_headers>readdicomfile at 66
> >> ret = read_dicom(fp, 'il',dict);
> >>
> >> Error in ==> spm_dicom_headers at 25
> >>    tmp = readdicomfile(P(i,:),dict);
> >>
> >> %% Here, '003_0001' is a dicom file. I am using SPM5 on Matlab R2007b
> >> with 1G RAM
> >>
> >>
> >> Thanks!




On 31 Mar 2009, at 15:31, Torben Ellegaard Lund wrote:

Dear Steven, John and others

I think the dicom converter in SPM does an excellent job, and when it comes to orientation I have seen nothing like it. I would actually argue that the people who are to blame are the ones who think that each slice needs its own DICOM file.

Best
Torben




Den 31/03/2009 kl. 15.17 skrev Steven Liu:

Dear John:

   I used SPM_DICOM_essential also in SPM8b, but it does not help.
The problem here is that when you try to convert too many fMRI DICOM files, for example,
if you have 300 volumes, each with 50 slices, you will have 15000 DICOM files
to convert into Analyze, then spm_dicom_convert will fail due to memory
problem.  Even if it does not fail,  it will take very very long time to complete
such a converting.   I think, this is a big bug since SPM2, SPM5 or SPM8b
has not resolved this problem.  SPM has to make a C+++ version for this function
or totally change the way of coding and processing in the next version of SPM.
At now, we can use the latest version of MRIConvert or MRICron (each of the two
software packages has a command-line exe file for you to run at a batch mode
without through a GUI)  to convert big fMRI DICOM files.
    But for a few number of DICOM files, spm_dicom_convert works excellently
becasue it takes care the origin much more accurately than any other software.

Steven

Steven




On Tue, Mar 31, 2009 at 7:35 AM, John Ashburner <[log in to unmask]> wrote:
The memory problems were occuring because all the header info was stored from
all the DICOM files, so that it could be sorted into different volumes.  A
more recent version of the converter only saves the essential fields in
memory.  This is available in SPM8b, but also may (not entirely sure) be
included among the recent updates for SPM5.

Best regards,
-John

On Tuesday 31 March 2009 03:52, Michael T Rubens wrote:
> try dicominfo instead of spm_dicom_headers (I think you need Image
> Processing Toolbox).
> Michael
>
> 2009/3/30 Steven Liu <[log in to unmask]>
>
> > I used to have the same problem when I converted more than 280 volumes,
> > each of
> > which had more than 40 slices. And it is very slow to use
> > SPM_DICOM_Convert to
> > convert fMRI DICOM files to Analyze. It is ok if you use it to convert a
> > few number of DICOM
> > files, such as Structural DICOM files.  You may use MRIConvert to convert
> > functional
> > DICOM when you have too many files.
> >
> >
> > Steven
> >
> >
> >
> > 2009/3/30 ±«Ãô <[log in to unmask]>
> >
> > Hi,
> >
> >> Excuse me for a beginner's question. I am trying to convert the original
> >>  dicom files to the format that can be recognized by SPM5. So I tried
> >> using
> >>  spm_dicom_convert and spm_dicom_headers. However, the following error
> >>
> >> messages appeared:
> >> >> spm_dicom_headers('003_0001');
> >>
> >> ??? Error using ==> fread
> >> Out of memory. Type HELP MEMORY for your options.
> >>
> >> Error in ==> spm_dicom_headers>decode_csa2 at 508
> >>        t(i).item(j).val = fread(fp,len,'*char')';
> >>
> >> Error in ==> spm_dicom_headers>decode_csa at 425
> >>    t = decode_csa2(fp,lim);
> >>
> >> Error in ==> spm_dicom_headers>read_dicom at 100
> >>                dat  = decode_csa(fp,tag.length);
> >>
> >> Error in ==> spm_dicom_headers>readdicomfile at 66
> >> ret = read_dicom(fp, 'il',dict);
> >>
> >> Error in ==> spm_dicom_headers at 25
> >>    tmp = readdicomfile(P(i,:),dict);
> >>
> >> %% Here, '003_0001' is a dicom file. I am using SPM5 on Matlab R2007b
> >> with 1G RAM
> >>
> >>
> >> Thanks!