NAMIC-Dartmouth-DWI-to-NRRD-Format

From NAMIC Wiki
Jump to: navigation, search
Home < NAMIC-Dartmouth-DWI-to-NRRD-Format

Note: please also see this page about NRRD headers which refer to the original image files, without the need for any additional data reading with MATLAB.

The following MATLAB script converts the Dartmouth DWIs into a single file in which the volumes (2 baselines and 12 diffusion weighted images) are in the appropriate space. The resulting raw image, together with a nrrd header, are used by Slicer to do DTI analysis.

fpout = fopen('nrrdraw.raw', 'w');
  for k = 1:14;
    % for subject 1,2,4,5 the slice order is Superior-Inferior, need to
    % reverse order
    % for m = 36:-1:1
    % for subject 3, 6, the slice order is Inferior-superior
    for m = 1:36
      n = (k-1)*36+m;
      % use appropriate dicom prefix
      name = sprintf('S8.%03d', n);
      fp = fopen(name);
      fseek(fp, -65536*2, 'eof');
      A = fread(fp, [256 256], 'short');
      fclose(fp);
      fwrite(fpout, A, 'short');
    end
   end
 fclose(fpout);