0001 function vb_dicom2curry(infile_pref,outfile_pref,flag)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 infile_suf = '';
0051 if exist([infile_pref '1.mri'])
0052 infile_suf = '.mri';
0053 elseif exist([infile_pref '1.dcm'])
0054 infile_suf = '.dcm';
0055 end
0056
0057 disp(['prefix: ' infile_pref]);
0058 disp(['sufix : ' infile_suf]);
0059
0060
0061
0062
0063 fprintf('\n');
0064 fprintf('--- Count num. of images ');
0065
0066 Nimg = 1;
0067 v_max = 0;
0068
0069 while 1
0070 if ~exist([infile_pref num2str(Nimg) infile_suf])
0071 Nimg = Nimg-1;
0072 break;
0073 end
0074 s = read_dicom([infile_pref num2str(Nimg) infile_suf]);
0075 v_max = max([v_max; s.pixel_data(:)]);
0076 clear s;
0077
0078 Nimg = Nimg+1;
0079
0080 if mod(Nimg,10) == 0
0081 fprintf('-');
0082 end
0083 end
0084
0085 fprintf(' %d files \n',Nimg);
0086
0087
0088
0089
0090 fprintf('--- Create header file\n');
0091
0092 s = read_dicom([infile_pref '1' infile_suf]);
0093
0094 fp = fopen([outfile_pref '.imd'],'w');
0095 fprintf(fp,'IMAGE_KEYWORDS START\n');
0096 fprintf(fp,'\tSLICE_DISTANCE\t= %f\n',s.slice_thickness);
0097 fprintf(fp,'\tSLICE_NR\t= %d\n',Nimg);
0098 fprintf(fp,'\tSLICE_VALID\t= %d\n',Nimg);
0099 fprintf(fp,'\tSLICE_NR1ST\t= 1\n');
0100 fprintf(fp,'\tRAW_IMAGE_FORMAT\t= 2\n');
0101 fprintf(fp,'\tRAW_NUMBER_OF_BITS\t= %d\n',s.bits_allocated);
0102 fprintf(fp,'\tRAW_MOST_SIGN_BIT\t= %d\n',s.high_bit);
0103 fprintf(fp,'\tRAW_OFFSET\t= 0\n');
0104 fprintf(fp,'\tRAW_PIXEL_SIZE_X\t= 1\n');
0105 fprintf(fp,'\tRAW_PIXEL_SIZE_Y\t= 1\n');
0106 fprintf(fp,'\tRAW_SIZE_X\t= %d\n',double(s.rows));
0107 fprintf(fp,'\tRAW_SIZE_Y\t= %d\n',double(s.columns));
0108 fprintf(fp,'\tSLICE_ORDER\t= 1\n');
0109 fprintf(fp,'IMAGE_KEYWORDS END');
0110 fclose(fp);
0111
0112
0113
0114
0115 if nargin == 3 & strcmp(flag,'header')
0116 return;
0117 else
0118 fprintf(['--- Save image data (' outfile_pref '.img)\n']);
0119
0120 Z = 65535/v_max;
0121 fp = fopen([outfile_pref '.img'],'w');
0122
0123 h = waitbar(0,'Save Curry image data');
0124 prg = 0;
0125 prg_all = Nimg;
0126 vb_disp_nonl(sprintf('%3d %% processed',ceil(100*(prg/prg_all))));
0127
0128 for i = 1:Nimg
0129 s = read_dicom([infile_pref num2str(i) infile_suf]);
0130
0131
0132 fwrite(fp,(s.pixel_data.*Z)','uint16');
0133 clear s;
0134
0135 if mod(i,10) == 0
0136 waitbar(i/Nimg);
0137 for ii=1:15; vb_disp_nonl(sprintf('\b')); end
0138 vb_disp_nonl(sprintf('%3d %% processed',ceil(100*(prg/prg_all))));
0139 end
0140 prg = prg+1;
0141 end
0142
0143 fclose(fp);
0144 close(h);
0145 drawnow;
0146 vb_disp_nonl(sprintf('\n'));
0147 end
0148
0149 return;