Changeset 103 for aedes_readfid.m
 Timestamp:
 Mar 10, 2010, 1:31:15 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

aedes_readfid.m
r99 r103 744 744 745 745 if isfield(procpar,'seqcon') 746 seqcon=procpar.seqcon{1};746 procpar.seqcon=procpar.seqcon{1}; 747 747 else 748 seqcon='nnnnn';748 procpar.seqcon='nnnnn'; 749 749 end 750 750 751 751 %% Determine acquisition type from seqcon parameter 752 if all( seqcon=='n') % 1D spectroscopy753 AcqType=1;754 elseif all( seqcon(4:5)=='n') % 2D imaging755 AcqType=2;756 elseif seqcon(5)=='n' % 3D imaging757 AcqType=3;752 if all(procpar.seqcon=='n') % 1D spectroscopy 753 Dat.AcqType=1; 754 elseif all(procpar.seqcon(4:5)=='n') % 2D imaging 755 Dat.AcqType=2; 756 elseif procpar.seqcon(5)=='n' % 3D imaging 757 Dat.AcqType=3; 758 758 else % 4D imaging 759 AcqType=4;759 Dat.AcqType=4; 760 760 end 761 761 762 762 %% Doublecheck that AcqType is not 1D spectral 763 763 if isfield(procpar,'nv') && procpar.nv==0 764 AcqType=1;764 Dat.AcqType=1; 765 765 end 766 766 … … 777 777 ~isempty(strfind(procpar.seqfil{1},'2PULSE'))  ... 778 778 ~isempty(strfind(procpar.seqfil{1},'2pulse')) 779 AcqType=1;779 Dat.AcqType=1; 780 780 end 781 781 … … 787 787 if isfield(procpar,'flash_converted') 788 788 if isfield(procpar,'ni') && procpar.ni>1 789 seqcon(3)='s';790 elseif (( seqcon(2)=='c') && (seqcon(3)=='c'))791 seqcon(2)='s';789 procpar.seqcon(3)='s'; 790 elseif ((procpar.seqcon(2)=='c') && (procpar.seqcon(3)=='c')) 791 procpar.seqcon(2)='s'; 792 792 end 793 793 UsePhaseTable=false; % Do not try to order data if flashc has been run … … 807 807 strcmp(procpar.array{1},'pad') && all(procpar.pad==0) 808 808 % Skip the array parsing if the array is a dummy "pad"array... 809 isAcqArrayed = false;810 ArrayLength = 1;811 else 812 isAcqArrayed = true;813 ArrayLength = [];809 Dat.isAcqArrayed = false; 810 Dat.ArrayLength = 1; 811 else 812 Dat.isAcqArrayed = true; 813 Dat.ArrayLength = []; 814 814 815 815 % Determine array length 816 816 for ii=1:length(procpar.array) 817 817 if iscell(procpar.array{ii}) 818 ArrayLength(ii) = length(procpar.(procpar.array{ii}{1}));818 Dat.ArrayLength(ii) = length(procpar.(procpar.array{ii}{1})); 819 819 else 820 ArrayLength(ii) = length(procpar.(procpar.array{ii}));821 end 822 end 823 ArrayLength = prod(ArrayLength);820 Dat.ArrayLength(ii) = length(procpar.(procpar.array{ii})); 821 end 822 end 823 Dat.ArrayLength = prod(Dat.ArrayLength); 824 824 end 825 825 else 826 isAcqArrayed = false;827 ArrayLength = 1;826 Dat.isAcqArrayed = false; 827 Dat.ArrayLength = 1; 828 828 end 829 829 … … 891 891 892 892 if ~Dat.FastDataRead 893 if any( AcqType==[1 2])894 switch seqcon(2:3)893 if any(Dat.AcqType==[1 2]) 894 switch procpar.seqcon(2:3) 895 895 case {'cc','sc'} 896 896 kspace = zeros(hdr.FileHeader.np/2,... … … 918 918 if Dat.ShowWaitbar 919 919 wb_h = aedes_wbar(0/hdr.FileHeader.nblocks,... 920 {['Reading ',num2str( AcqType),'D VNMR data (seqcon: "'seqcon '")'],...920 {['Reading ',num2str(Dat.AcqType),'D VNMR data (seqcon: "' procpar.seqcon '")'],... 921 921 ['(Processing data block ' ... 922 922 num2str(0) '/' num2str(hdr.FileHeader.nblocks) ')']}); … … 929 929 aedes_wbar(ii/hdr.FileHeader.nblocks,... 930 930 wb_h,... 931 {['Reading ',num2str( AcqType),'D VNMR data (seqcon: "'seqcon '")'],...931 {['Reading ',num2str(Dat.AcqType),'D VNMR data (seqcon: "' procpar.seqcon '")'],... 932 932 ['(Processing data block ' ... 933 933 num2str(ii) '/' num2str(hdr.FileHeader.nblocks) ')']}) … … 1027 1027 1028 1028 %% Store and order kspace values 1029 if any( AcqType==[1 2])1030 switch seqcon(2:3)1029 if any(Dat.AcqType==[1 2]) 1030 switch procpar.seqcon(2:3) 1031 1031 case {'cc','sc'} 1032 1032 kspace(:,:,ii) = complex_block; … … 1058 1058 % Initialize waitbar 1059 1059 if Dat.ShowWaitbar 1060 wb_h = aedes_calc_wait(['Reading ',num2str( AcqType),...1061 'D VNMR data (seqcon: "' seqcon '")']);1060 wb_h = aedes_calc_wait(['Reading ',num2str(Dat.AcqType),... 1061 'D VNMR data (seqcon: "' procpar.seqcon '")']); 1062 1062 end 1063 1063 … … 1128 1128 1129 1129 %% Store and order kspace values 1130 if any( AcqType==[1 2])1131 switch seqcon(2:3)1130 if any(Dat.AcqType==[1 2]) 1131 switch procpar.seqcon(2:3) 1132 1132 case {'cc','sc'} 1133 1133 %kspace(:,:,ii) = complex_block; … … 1146 1146 end 1147 1147 1148 1149 1148 % Remove singleton dimensions from kspace 1150 1149 kspace = squeeze(kspace); … … 1156 1155 delete(wb_h) 1157 1156 end 1158 return1159 end1160 1161 %% Support for fat/water measurements 1162 if isfield(procpar,'seqfil') && strcmpi(procpar.seqfil,'ge3d_csi2')1163 1164 % Split kspace into fat and water (in 4th dimesion)1165 kspace=reshape(permute(reshape(kspace,256,2,[]),[1 3 4 2]),256,128,[],2);1166 1167 % Fourier transform data1168 if any(Dat.ZeroPadding==[1 2])1169 data_sz = [procpar.np/2,procpar.nf,procpar.nv2,2];1170 data = zeros(data_sz,class(kspace));1171 data(:,:,:,1) = abs(fftshift(fftn(kspace(:,:,:,1),data_sz(1:3))));1172 data(:,:,:,2) = abs(fftshift(fftn(kspace(:,:,:,2),data_sz(1:3))));1173 else1174 data = zeros(size(kspace),class(kspace));1175 data(:,:,:,1) = abs(fftshift(fftn(kspace(:,:,:,1))));1176 data(:,:,:,2) = abs(fftshift(fftn(kspace(:,:,:,2))));1177 end1178 1179 % Delete kspace if not returned1180 if ~Dat.ReturnKSpace1181 kspace=[];1182 end1183 1184 1157 return 1185 1158 end … … 1272 1245 end 1273 1246 1274 %%  1247 %% Support for fat/water measurements  1248 if isfield(procpar,'seqfil') && strcmpi(procpar.seqfil,'ge3d_csi2') 1249 1250 % Split kspace into fat and water (in 4th dimesion) 1251 kspace=reshape(permute(reshape(kspace,256,2,[]),[1 3 4 2]),256,128,[],2); 1252 1253 % Fourier transform data 1254 if any(Dat.ZeroPadding==[1 2]) 1255 data_sz = [procpar.np/2,procpar.nf,procpar.nv2,2]; 1256 data = zeros(data_sz,class(kspace)); 1257 data(:,:,:,1) = abs(fftshift(fftn(kspace(:,:,:,1),data_sz(1:3)))); 1258 data(:,:,:,2) = abs(fftshift(fftn(kspace(:,:,:,2),data_sz(1:3)))); 1259 else 1260 data = zeros(size(kspace),class(kspace)); 1261 data(:,:,:,1) = abs(fftshift(fftn(kspace(:,:,:,1)))); 1262 data(:,:,:,2) = abs(fftshift(fftn(kspace(:,:,:,2)))); 1263 end 1264 1265 % Delete kspace if not returned 1266 if ~Dat.ReturnKSpace 1267 kspace=[]; 1268 end 1269 1270 return 1271 end 1272 1273 % Check the number of receivers (PI stuff) 1274 if isfield(procpar,'rcvrs') && ~isempty(procpar.rcvrs) 1275 % Multiple receivers used 1276 nRcv = length(find(procpar.rcvrs{1}=='y')); 1277 data = []; 1278 kspace2 = []; 1279 for ii=1:nRcv 1280 tmp_kspace = l_ReconstructKspace(kspace(:,:,ii),procpar,Dat); 1281 kspace2(:,:,:,ii)=tmp_kspace; 1282 if Dat.ReturnFTData 1283 tmp_data = l_CalculateFFT(tmp_kspace,procpar,Dat); 1284 data(:,:,:,ii) = tmp_data; 1285 end 1286 end 1287 kspace = kspace2; 1288 kspace2=[]; 1289 else 1290 % Only one receiver 1291 kspace = l_ReconstructKspace(kspace,procpar,Dat); 1292 data = l_CalculateFFT(kspace,procpar,Dat); 1293 end 1294 1295 % Delete kspace if not returned 1296 if ~Dat.ReturnKSpace 1297 kspace=[]; 1298 end 1299 1300 %=============================================== 1301 % Reconstruct kspace for different sequences 1302 %=============================================== 1303 function kspace=l_ReconstructKspace(kspace,procpar,Dat) 1304 1275 1305 1276 1306 %% Flip images for certain measurements … … 1298 1328 1299 1329 % Handle arrayed and RARE sequences 1300 if isAcqArrayed &&AcqType~=1 && Dat.Sorting && ~Dat.isEPIdata1301 %if ~strcmpi( seqcon(2:3),'cc') && ( isempty(Dat.phasetable)  ...1330 if Dat.isAcqArrayed && Dat.AcqType~=1 && Dat.Sorting && ~Dat.isEPIdata 1331 %if ~strcmpi(procpar.seqcon(2:3),'cc') && ( isempty(Dat.phasetable)  ... 1302 1332 % isfield(procpar,'flash_converted') ) 1303 if (( isempty(Dat.phasetable) && ~strcmpi( seqcon(2:3),'sc') ) && ...1304 ~(strcmpi( seqcon(2:3),'cc') &&ArrayLength==size(kspace,3)))  ...1333 if (( isempty(Dat.phasetable) && ~strcmpi(procpar.seqcon(2:3),'sc') ) && ... 1334 ~(strcmpi(procpar.seqcon(2:3),'cc') && Dat.ArrayLength==size(kspace,3)))  ... 1305 1335 isfield(procpar,'flash_converted') 1306 1336 1307 1337 % Sort uncompressed arrayed data 1308 ks_order = 1:procpar.nv* ArrayLength;1338 ks_order = 1:procpar.nv*Dat.ArrayLength; 1309 1339 tmp = 0:procpar.nv:(procpar.ne1)*procpar.nv; 1310 tmp=repmat(tmp,procpar.nv* ArrayLength,1);1311 ks_order = reshape(ks_order, ArrayLength,procpar.nv).';1340 tmp=repmat(tmp,procpar.nv*Dat.ArrayLength,1); 1341 ks_order = reshape(ks_order,Dat.ArrayLength,procpar.nv).'; 1312 1342 ks_order = ks_order(:); 1313 1343 ks_order = repmat(ks_order,1,procpar.ne); … … 1322 1352 1323 1353 % Reshape into 3D matrix 1324 kspace=reshape(kspace,[size(kspace,1) procpar.nv ArrayLength* ...1354 kspace=reshape(kspace,[size(kspace,1) procpar.nv Dat.ArrayLength* ... 1325 1355 procpar.ns]); 1326 1356 else … … 1328 1358 if UsePhaseTable && ~isempty(Dat.phasetable) 1329 1359 %Dat.phasetable = Dat.phasetable'; 1330 if isAcqArrayed && ArrayLength>1 && strcmpi(seqcon(2:3),'cs')1331 kspace = permute(reshape(reshape(kspace,size(kspace,1),[]),size(kspace,1), ArrayLength,[]),[1 3 2]);1360 if Dat.isAcqArrayed && Dat.ArrayLength>1 && strcmpi(procpar.seqcon(2:3),'cs') 1361 kspace = permute(reshape(reshape(kspace,size(kspace,1),[]),size(kspace,1),Dat.ArrayLength,[]),[1 3 2]); 1332 1362 else 1333 1363 Dat.phasetable = Dat.phasetable.'; … … 1406 1436 % patches that hopefully work... 1407 1437 1408 if strcmp( seqcon,'nncnn')1438 if strcmp(procpar.seqcon,'nncnn') 1409 1439 kspace = permute(kspace,[1 3 2]); 1410 elseif strcmp( seqcon,'nccnn') && length(size(kspace))==2 && ...1411 procpar.ns>=1 && AcqType~=11440 elseif strcmp(procpar.seqcon,'nccnn') && length(size(kspace))==2 && ... 1441 procpar.ns>=1 && Dat.AcqType~=1 1412 1442 if ~isempty(Dat.phasetable) 1413 1443 kssz = size(kspace); … … 1428 1458 end 1429 1459 1430 elseif strcmp( seqcon,'nscsn') && length(size(kspace))==3 && ...1431 AcqType~=11460 elseif strcmp(procpar.seqcon,'nscsn') && length(size(kspace))==3 && ... 1461 Dat.AcqType~=1 1432 1462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1433 1463 % Support for 3D fast spinecho … … 1451 1481 1452 1482 1453 elseif AcqType~=1 && isfield(procpar,'nv')1483 elseif Dat.AcqType~=1 && isfield(procpar,'nv') 1454 1484 if length(size(kspace))==2 && ... 1455 1485 ( size(kspace,1)~=(procpar.np/2)  size(kspace,2)~=procpar.nv ) … … 1467 1497 1468 1498 %%% Support for Teemu's ASE3Ddata 1469 %if strcmpi( seqcon,'ncccn')1499 %if strcmpi(procpar.seqcon,'ncccn') 1470 1500 % %% Reshape the kspace to the appropriate size 1471 1501 % kspace=reshape(kspace,[procpar.np/2 procpar.nv size(kspace,2)/procpar.nv]); … … 1474 1504 1475 1505 1506 1507 %========================================= 1508 % Fourier Transform Data 1509 %========================================= 1510 function data=l_CalculateFFT(kspace,procpar,Dat) 1511 data=[]; 1512 1476 1513 % Return image/spectral data  1477 1514 if Dat.ReturnFTData 1478 1515 %% Fourier transform spectral data 1479 if AcqType==11516 if Dat.AcqType==1 1480 1517 wb_h = aedes_wbar(0,'Fourier transforming spectral data'); 1481 1518 %data=zeros(size(kspace),'single'); … … 1547 1584 1548 1585 %% Fourier transform 2D and EPI image data 1549 if AcqType==2  Dat.isEPIdata1586 if Dat.AcqType==2  Dat.isEPIdata 1550 1587 sz=size(kspace,3); 1551 1588 … … 1582 1619 if Dat.ZeroPadding==2 1583 1620 if isfield(procpar,'lpe2') && isfield(procpar,'lpe') 1584 data_sz(3) = max(1,round((procpar.lpe2/procpar.lpe)*data_sz(2)* ArrayLength));1621 data_sz(3) = max(1,round((procpar.lpe2/procpar.lpe)*data_sz(2)*Dat.ArrayLength)); 1585 1622 end 1586 1623 end … … 1600 1637 % Reorient images and remove the reference image if requested 1601 1638 if Dat.OrientImages && ~isempty(procpar) && ... 1602 isfield(procpar,'orient') && any( AcqType==[2 3 4])1639 isfield(procpar,'orient') && any(Dat.AcqType==[2 3 4]) 1603 1640 orient = procpar.orient{1}; 1604 1641 if any(strcmpi(orient,{'xyz','trans90','cor90','sag90'})) … … 1614 1651 1615 1652 % $$$ %% Fourier transform 4D image data 1616 % $$$ elseif AcqType==41653 % $$$ elseif Dat.AcqType==4 1617 1654 % $$$ data = abs(fftshift(fftshift(fft2(kspace),2),1)); 1618 1655 end 1619 end 1620 1621 %% Delete waitbar 1622 if Dat.ShowWaitbar && ishandle(wb_h) 1623 delete(wb_h) 1624 end 1625 1626 % Delete kspace if not returned 1627 if ~Dat.ReturnKSpace 1628 kspace=[]; 1629 end 1656 1657 %% Delete waitbar 1658 if Dat.ShowWaitbar && ishandle(wb_h) 1659 delete(wb_h) 1660 end 1661 end 1662 1663 1664 1665 1630 1666 1631 1667 %========================================================
Note: See TracChangeset
for help on using the changeset viewer.