0

I'm writing a program in IDL to read DICOM images, then store them in a big matrix and finally save them in .dat file. The DICOMs are under the name IM0,IM1,IM2,..IM21777. I wrote the code below but I am getting an error. I am using IDL version 6.4.

files = file_search('E:\SE7\IM*)
n_files = n_elements(files)

full_data = fltarr(256,256,n_files)

for i=0L, n_files-1 do begin 
    full_data[*,*,i] = read_dicom('E:\SE7\IM')
endfor

path  = 'E:\'
open, 1, path + "full_data.dat'
writeu, 1, full_data
close, 1

I am not sure how to loop over the DICOM name i.e. IM0, IM1,IM2 etc

After I store them in the big matrix (i.e. full_data =[256,256,2178]) I would like to make the 3D matrix 4D. Is that possible? I would like to make it have the dimensions [256, 256, 22, 99] i.e. 2178/99.

asynchronos
  • 583
  • 2
  • 14
user161260
  • 121
  • 2

1 Answers1

0

I'm not sure what error you are getting, but you are missing a quotation mark in the first line. It should be:

files = file_search('E:\SE7\IM*')

To loop over the DICOM name, you can string concatenate the loop index using + and STRTRIM() as follows:

for i=0L, n_files-1 do begin 
    full_data[*,*,i] = read_dicom('E:\SE7\IM'+STRTRIM(i,2))
endfor

Finally, to turn your (256,256,2178) matrix into a (256,256,22,99) matrix, use REBIN:

final_data = REBIN(full_data, 256, 256, 20, 99)

Depending on the way you want the dimensions arranged, you may need additional operations. This post is a great primer on how to manipulate arrays and their dimensionality: Coyote Dimensional Juggling Tutorial.

Steve G
  • 182
  • 9