0001 tic
0002
0003
0004
0005 getDicomsgui
0006
0007 disp('Calculating tensor...')
0008
0009 noise=evalin('base','noise');
0010 doFAmap=evalin('base','doFAmap');
0011 dotADC=evalin('base','dotADC');
0012 dolambda1=evalin('base','dolambda1');
0013 dolambda2=evalin('base','dolambda2');
0014 dolambda3=evalin('base','dolambda3');
0015 docm=evalin('base','docm');
0016 counter=evalin('base','counter');
0017 extension=evalin('base','extension');
0018
0019
0020 slices=counter/7;
0021
0022
0023 FAmaps=[];
0024 tADCmaps=[];
0025 lambda1_maps=[];
0026 lambda2_maps=[];
0027 lambda3_maps=[];
0028 cmaps=[];
0029 xyzmaps=[];
0030
0031
0032
0033
0034
0035
0036
0037 warning off MATLAB:divideByZero
0038
0039
0040 for numslice=1:slices
0041
0042 bo=tensorvol(:,:,numslice,1);
0043 b1=tensorvol(:,:,numslice,2);
0044 b2=tensorvol(:,:,numslice,3);
0045 b3=tensorvol(:,:,numslice,4);
0046 b4=tensorvol(:,:,numslice,5);
0047 b5=tensorvol(:,:,numslice,6);
0048 b6=tensorvol(:,:,numslice,7);
0049
0050
0051 ADC101=log(im2double(b1)./im2double(bo))./(-1000);
0052 ADC_101=log(im2double(b2)./im2double(bo))./(-1000);
0053 ADC011=log(im2double(b3)./im2double(bo))./(-1000);
0054 ADC01_1=log(im2double(b4)./im2double(bo))./(-1000);
0055 ADC110=log(im2double(b5)./im2double(bo))./(-1000);
0056 ADC_110=log(im2double(b6)./im2double(bo))./(-1000);
0057
0058 transform=[1 1 0 2 0 0;1 0 1 0 2 0;0 1 1 0 0 2;1 1 0 -2 0 0;1 0 1 0 -2 0;0 1 1 0 0 -2];
0059
0060 xx=zeros(256);
0061 yy=zeros(256);
0062 zz=zeros(256);
0063 xy=zeros(256);
0064 xz=zeros(256);
0065 yz=zeros(256);
0066 lambda1=zeros(256);
0067 lambda2=zeros(256);
0068 lambda3=zeros(256);
0069 r=zeros(256);
0070 g=zeros(256);
0071 b=zeros(256);
0072 FAmap=zeros(256);
0073 tADC=zeros(256);
0074
0075 for i=1:256
0076 for j=1:256
0077 if (bo(i,j)>noise)
0078 ADCm=[ADC110(i,j);ADC101(i,j);ADC011(i,j);ADC_110(i,j);ADC_101(i,j);ADC01_1(i,j)];
0079 ADCe=inv(transform)*ADCm;
0080 xx(i,j)=ADCe(1,1);
0081 yy(i,j)=ADCe(2,1);
0082 zz(i,j)=ADCe(3,1);
0083 xy(i,j)=ADCe(4,1);
0084 xz(i,j)=ADCe(5,1);
0085 yz(i,j)=ADCe(6,1);
0086 ten=[xx(i,j) xy(i,j) xz(i,j);xy(i,j) yy(i,j) yz(i,j);xz(i,j) yz(i,j) zz(i,j)];
0087 [V,D]=eig(ten);
0088 D=eig(ten);
0089 D=abs(D);
0090 E=D;
0091 D=sort(D);
0092 e1=D(3,1);e1=e1*2;
0093 e2=D(2,1);e2=e2*2;
0094 e3=D(1,1);e3=e3*2;
0095 lambda1(i,j)=e1;
0096 lambda2(i,j)=e2;
0097 lambda3(i,j)=e3;
0098
0099 largest=find(E==D(3,1));
0100 sz=length(largest);
0101 r(i,j)=V(1,largest(sz));
0102 g(i,j)=V(2,largest(sz));
0103 b(i,j)=V(3,largest(sz));
0104 trace=(e1+e2+e3)/3;
0105
0106 FA=(sqrt(3*((e1-trace)^2+(e2-trace)^2+(e3-trace)^2)))/(sqrt(2*(e1^2+e2^2+e3^2)));
0107 tADC(i,j)=trace;
0108 FAmap(i,j)=FA;
0109 end;
0110 end;
0111 end;
0112
0113
0114
0115
0116 rgb=cat(3,r,g,b);
0117 xyz=cat(3,r,(g*-1),b);
0118 FAmap3=cat(3,FAmap,FAmap,FAmap);
0119 cm=abs(rgb).*FAmap3;
0120
0121
0122
0123
0124
0125
0126 FAmaps=cat(3,FAmaps,FAmap);
0127 tADCmaps=cat(3,tADCmaps,tADC);
0128 lambda1_maps=cat(3,lambda1_maps,lambda1);
0129 lambda2_maps=cat(3,lambda2_maps,lambda2);
0130 lambda3_maps=cat(3,lambda3_maps,lambda3);
0131 cmaps=cat(4,cmaps,cm);
0132 xyzmaps=cat(4,xyzmaps,xyz);
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147 if (doFAmap==1)
0148 number=num2str(numslice);
0149 st1='FA';st2='.dcm';
0150 nameforfile=[st1 number st2];
0151 dicomwrite(FAmap,nameforfile);
0152 disp('writing FA map to DICOM file')
0153 end
0154
0155
0156
0157 if (dotADC==1)
0158 number=num2str(numslice);
0159 st1='tADC';st2='.dcm';
0160 nameforfile=[st1 number st2];
0161 dicomwrite(tADC,nameforfile);
0162 disp('writing tADC map to DICOM file')
0163 end
0164
0165
0166
0167 if (dolambda1==1)
0168 number=num2str(numslice);
0169 st1='lambda1_';st2='.dcm';
0170 nameforfile=[st1 number st2];
0171 dicomwrite(lambda1,nameforfile);
0172 disp('writing lambda1 map to DICOM file')
0173 end
0174
0175
0176
0177 if (dolambda2==1)
0178 number=num2str(numslice);
0179 st1='lambda2_';st2='.dcm';
0180 nameforfile=[st1 number st2];
0181 dicomwrite(lambda2,nameforfile);
0182 disp('writing lambda2 map to DICOM file')
0183 end
0184
0185
0186
0187 if (dolambda3==1)
0188 number=num2str(numslice);
0189 st1='lambda3_';st2='.dcm';
0190 nameforfile=[st1 number st2];
0191 dicomwrite(lambda3,nameforfile);
0192 disp('writing lambda3 map to DICOM file')
0193 end
0194
0195
0196
0197 if (docm==1)
0198 number=num2str(numslice);
0199 st1='cm';st2='.dcm';
0200 nameforfile=[st1 number st2];
0201 dicomwrite(cm,nameforfile);
0202 disp('writing colormap to DICOM file')
0203 end
0204
0205 mes=[num2str(numslice) ' of ' num2str(slices) ' finished'];
0206 disp(mes)
0207 end
0208
0209
0210 clear FA FAmap tADC lambda1 lambda2 lambda3 cm FAmap3 rgb bo b1 b2 b3 b4 b5 b6 ADC101 ADC_101 ADC011;
0211 clear ADC01_1 ADC110 ADC_110 r g b xx yy zz xy xz yz trace ten tensorvol transform ADCe ADCm D V;
0212 assignin('base','tensorvol',0)
0213
0214
0215 assignin('base','FAmaps',FAmaps);
0216 assignin('base','tADCmaps',tADCmaps);
0217 assignin('base','lambda1_maps',lambda1_maps);
0218 assignin('base','lambda2_maps',lambda2_maps);
0219 assignin('base','lambda3_maps',lambda3_maps);
0220 assignin('base','cmaps',cmaps);
0221 assignin('base','xyzmaps',xyzmaps);
0222
0223 toc