1 function [Sk,Sk2] = dpg_recon( Fin, N, dk, nky );
2 % reconstruct measured EPI data using Dual-Polarity GRAPPA kernels
5 % Copyright 2004-2016 W. Scott Hoge (wsh032580 at proton dot me)
7 % Licensed under the terms of the MIT License
8 % (https://opensource.org/licenses/MIT)
10 Sk = zeros(size(Fin{1}));
12 Sk2 = zeros(size(Fin{1}));
22 nky = str2num(kernel(1));
25 if ( ~isfield( N, 'n') & isfield( N, 'coef' ) )
27 N(cnt).n = N(cnt).coef;
31 nkx = size(N(1).n,1) / size(Fin{1},3) / nky;
34 % fprintf(' ky:%d kx:%d nc:%d\n',nky,nkx,ncoils);
35 indx3 = ceil((0-nkx)/2) -1 + (1:nkx); % [-2:2];
40 % for kycnt=2:2*dk:(size(Sk,1)-2*dk),
41 for kycnt=2:2*dk:(size(Sk,1)),
43 % fprintf('---%d ---\n',kycnt);
44 for patcnt = 1:length(N); % [ 2:length(N)/2 (length(N)/2+(2:length(N)/2)) ];
46 % fprintf(' %d',patcnt)
47 v = extrapolate_pattern(N(patcnt).pattern,nky);
49 if (patcnt <= length(N)/2)
50 indx = kycnt + (patcnt-1) + v;
52 indx = kycnt + (patcnt-2) + v;
55 % fprintf(': '); fprintf(' %d', indx); fprintf('\n');
57 indx = mod( indx, sz(1) );
58 indx( indx==0 ) = sz(1);
60 % fprintf('# '); fprintf(' %d', indx); fprintf('\n');
62 %% recon k-space line based on that pattern:
63 A = zeros( size(Sk,2), length(indx3)*length(v)*size(Sk,3) );
65 for cnt3=1:length(indx3),
66 y0 = mod( indx3(cnt3) + [1:size(Sk,2)] , size(Sk,2) );
67 y0( y0 == 0 ) = size(Sk,2);
69 tmpSk = zeros([ length(indx) length(y0) size(Sk,3) ]);
71 if (patcnt <= length(N)/2)
72 tmpSk(1:2:end,:,:) = Fin{1}( indx(1:2:end), y0, :);
73 tmpSk(2:2:end,:,:) = Fin{2}( indx(2:2:end), y0, :);
75 tmpSk(1:2:end,:,:) = Fin{2}( indx(1:2:end), y0, :);
76 tmpSk(2:2:end,:,:) = Fin{1}( indx(2:2:end), y0, :);
79 A( (1:size(Sk,2)), (cnt3-1)*nky*ncoils + (1:nky*ncoils) ) = ...
80 reshape( permute( tmpSk, [ 2 1 3 ]), ...
81 size(Sk,2), size(Sk,3)*length(indx) );
85 if (verbose), % ( sum(Sk(Y(mss(cnt2))+1,:,l)) ~= 0 );
87 if (patcnt > length(N)/2); tmp = tmp-1; end;
88 rptupd(prnt,sprintf(' %3d',[ tmp; indx(:) ]));
89 rptupd(prnt,sprintf(' (pattern: %s)', N(patcnt).pattern) );
92 figure(1); imagesc( log10(abs(Sk(:,:,1)) + 1e-1) ); pause(0.5);
96 % linerpt(cnt2) = 'x';
103 % if cnt2==109, keyboard; end;
104 % rptupd(prnt,(' line %3d, pattern %3d\n', cnt2, plist(cnt3) );
107 tmp = kycnt+(patcnt);
108 if (patcnt > length(N)/2), tmp = tmp-1; end;
109 Sk( tmp, :, l ) = [A] * n(:,l);
111 if (patcnt > length(N)/2 ),
112 Sk2( kycnt+(patcnt-1), :, l ) = [A] * n(:,l);
114 Sk( kycnt+(patcnt), :, l ) = [A] * n(:,l);
119 % if (verbose>1), keyboard; end;
124 Sk = Sk(1:sz(1),:,:);
126 %% need to fix this above, but for now...
127 Sk = Sk([2:sz(1) 1],:,:); % rotate the output back 1 kspace line
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 function rptupd( prnt, str )
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 function v = extrapolate_pattern(p,YKS)
141 r = find( (p == 'x') | (p == '<' ) | (p == '>') );
142 v = find( (p == '*') | (p == '<' ) | (p == '>') ) - r;
145 v = v( find( v~= 0 ) );