Skip to content

Commit

Permalink
shift_rec2 --> shift_rec
Browse files Browse the repository at this point in the history
  • Loading branch information
epnev committed Jan 15, 2017
1 parent b04f3cb commit f620dc1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions apply_shifts.m
Expand Up @@ -90,15 +90,15 @@
Yfft = cellfun(@(x) fftn(x),Yc,'un',0);
end
if all(options.mot_uf == 1)
M_fin = shift_reconstruct2(Yfft{1},shifts_temp(ii).shifts,shifts_temp(ii).diff,options.us_fac,Nr{1},Nc{1},Np{1},'NaN',0);
M_fin = shift_reconstruct(Yfft{1},shifts_temp(ii).shifts,shifts_temp(ii).diff,options.us_fac,Nr{1},Nc{1},Np{1},'NaN',0);
if nd == 2; Mf{ii} = M_fin; end
if nd == 3; Mf{ii} = M_fin; end
else
shifts_up = shifts_temp(ii).shifts_up;
for i = 1:length(xx_uf)
for j = 1:length(yy_uf)
for k = 1:length(zz_uf)
M_fin{i,j,k} = shift_reconstruct2(Yfft{i,j,k},shifts_up(i,j,k,:),shifts(t).diff(i,j,k),options.us_fac,Nr{i,j,k},Nc{i,j,k},Np{i,j,k},'NaN',0);
M_fin{i,j,k} = shift_reconstruct(Yfft{i,j,k},shifts_up(i,j,k,:),shifts(t).diff(i,j,k),options.us_fac,Nr{i,j,k},Nc{i,j,k},Np{i,j,k},'NaN',0);
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion normcorre.m
Expand Up @@ -313,7 +313,7 @@
for k = 1:length(zz_uf)
extended_grid = [max(xx_us(i)-overlap_post(1),1),min(xx_uf(i)+overlap_post(1),d1),max(yy_us(j)-overlap_post(2),1),min(yy_uf(j)+overlap_post(2),d2),max(zz_us(k)-overlap_post(3),1),min(zz_uf(k)+overlap_post(3),d3)];
I_temp = Yt(extended_grid(1):extended_grid(2),extended_grid(3):extended_grid(4),extended_grid(5):extended_grid(6));
M_fin{i,j,k} = shift_reconstruct2(I_temp,shifts_up(i,j,k,:),diff_up(i,j,k),us_fac,Nr{i,j,k},Nc{i,j,k},Np{i,j,k},'NaN',add_value);
M_fin{i,j,k} = shift_reconstruct(I_temp,shifts_up(i,j,k,:),diff_up(i,j,k),us_fac,Nr{i,j,k},Nc{i,j,k},Np{i,j,k},'NaN',add_value);
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion normcorre_batch.m
Expand Up @@ -267,7 +267,7 @@
for k = 1:length(zz_uf)
extended_grid = [max(xx_us(i)-overlap_post(1),1),min(xx_uf(i)+overlap_post(1),d1),max(yy_us(j)-overlap_post(2),1),min(yy_uf(j)+overlap_post(2),d2),max(zz_us(k)-overlap_post(3),1),min(zz_uf(k)+overlap_post(3),d3)];
I_temp = Yt(extended_grid(1):extended_grid(2),extended_grid(3):extended_grid(4),extended_grid(5):extended_grid(6));
M_fin{i,j,k} = shift_reconstruct2(I_temp,shifts_up(i,j,k,:),diff_up(i,j,k),us_fac,Nr{i,j,k},Nc{i,j,k},Np{i,j,k},'NaN',add_value);
M_fin{i,j,k} = shift_reconstruct(I_temp,shifts_up(i,j,k,:),diff_up(i,j,k),us_fac,Nr{i,j,k},Nc{i,j,k},Np{i,j,k},'NaN',add_value);
end
end
end
Expand Down
20 changes: 5 additions & 15 deletions shift_reconstruct2.m → old/shift_reconstruct.m
@@ -1,10 +1,9 @@
function I = shift_reconstruct2(Y,shifts,diffphase,us_fac,Nr,Nc,Np,method,add_value)
function I = shift_reconstruct(Y,shifts,us_fac,Nr,Nc,Np,method,add_value)

% applies 3-d sub-pixel shifts to an input image
% INPUTS:
% Y: input image (double 3d tensor) in space (real) or frequency (complex) domain
% shifts: shifts
% diffphase: phase difference
% us_fac: upsampling factor for subpixel shifts
% method: method for treating boundaries
% add_value: value to add when zero-ing out boundaries
Expand All @@ -14,12 +13,6 @@

% Written by Eftychios A. Pnevmatikakis, Simons Foundation, 2016

if isreal(Y);
buf2ft = fftn(Y);
else
buf2ft = Y;
end

if nargin < 8 || isempty(add_value); add_value = 0; end
if nargin < 7 || isempty(method); method = 'zero'; end

Expand All @@ -35,22 +28,19 @@
col_shift = shifts(2);
if ismatrix(Y); pln_shift = 0; else pln_shift = shifts(3); end
shifts = [row_shift,col_shift,pln_shift];
buf2ft = fftn(Y);

if us_fac > 0
if isvector(Nc); [Nc,Nr,Np] = meshgrid(Nc,Nr,Np); end
Greg = buf2ft.*exp(1i*2*pi*(-row_shift*Nr/nr-col_shift*Nc/nc-pln_shift*Np/np));
elseif us_fac == 0
Greg = buf2ft;
end
Greg = Greg*exp(1i*diffphase);

I = real(ifftn(Greg));
I = remove_boundaries(I,shifts,method,add_value);
I = remove_boundaries(I,shifts,method,add_value);
else
if isreal(Y)
I = Y;
else
I = real(ifftn(Y));
end
I = Y;
end

end
20 changes: 15 additions & 5 deletions shift_reconstruct.m
@@ -1,9 +1,10 @@
function I = shift_reconstruct(Y,shifts,us_fac,Nr,Nc,Np,method,add_value)
function I = shift_reconstruct(Y,shifts,diffphase,us_fac,Nr,Nc,Np,method,add_value)

% applies 3-d sub-pixel shifts to an input image
% INPUTS:
% Y: input image (double 3d tensor) in space (real) or frequency (complex) domain
% shifts: shifts
% diffphase: phase difference
% us_fac: upsampling factor for subpixel shifts
% method: method for treating boundaries
% add_value: value to add when zero-ing out boundaries
Expand All @@ -13,6 +14,12 @@

% Written by Eftychios A. Pnevmatikakis, Simons Foundation, 2016

if isreal(Y);
buf2ft = fftn(Y);
else
buf2ft = Y;
end

if nargin < 8 || isempty(add_value); add_value = 0; end
if nargin < 7 || isempty(method); method = 'zero'; end

Expand All @@ -28,19 +35,22 @@
col_shift = shifts(2);
if ismatrix(Y); pln_shift = 0; else pln_shift = shifts(3); end
shifts = [row_shift,col_shift,pln_shift];
buf2ft = fftn(Y);

if us_fac > 0
if isvector(Nc); [Nc,Nr,Np] = meshgrid(Nc,Nr,Np); end
Greg = buf2ft.*exp(1i*2*pi*(-row_shift*Nr/nr-col_shift*Nc/nc-pln_shift*Np/np));
elseif us_fac == 0
Greg = buf2ft;
end

Greg = Greg*exp(1i*diffphase);
I = real(ifftn(Greg));
I = remove_boundaries(I,shifts,method,add_value);
I = remove_boundaries(I,shifts,method,add_value);
else
I = Y;
if isreal(Y)
I = Y;
else
I = real(ifftn(Y));
end
end

end

0 comments on commit f620dc1

Please sign in to comment.