%% for reshaping data to use SIM reconstruction _2D
size = wavelength_SI.*Nlambda;

simafrequency = 1/(wavelength_SI/(2.*1.1*0.9));

%% variables for 2D or 3D SIM (choose one if needed)
%parameter_for2DSIM
    Nbeam = 2;
    angles = [0 2*pi/3 4*pi/3];
    phi = [0 2*pi/3 4*pi/3];
    
%parameter_for3DSIM
    % Nbeam = 3;
    % angles = [0 2*pi/3 4*pi/3];
    % phi = [0 2*pi/5 4*pi/5 6*pi/5 8*pi/5];


%% ConventionalSI
zstack_SI_temp = reshape(permute(xy_image_SI, [1 2 4 3]),[N, N, N*Nangle*Nphase]);
zstackimages_SI = zeros(256,256,256);
for i = 1:256
    images_recon = SIM_reconstruction(zstack_SI_temp(:,:,Nangle*Nphase*(i-1)+1:Nangle*Nphase*i),size,simafrequency,angles,phi,Nbeam);
    zstackimages_SI(:,:,i) = images_recon(:,:,2);
end

%% sheetSI_low
zstack_lowsheetSI_temp = reshape(permute(xy_image_lowNAsheetSI, [1 2 4 3]),[N, N, N*Nangle*Nphase]);
zstackimages_lowsheetSI = zeros(256,256,256);
for i = 1:256
    images_recon = SIM_reconstruction(zstack_lowsheetSI_temp(:,:,Nangle*Nphase*(i-1)+1:Nangle*Nphase*i),size,simafrequency,angles,phi,Nbeam);
    zstackimages_lowsheetSI(:,:,i) = images_recon(:,:,2);
end

%% sheet_SI
zstack_sheetSI_temp = reshape(permute(xy_image_sheetSI, [1 2 4 3]),[N, N, N*Nangle*Nphase]);
zstackimages_sheetSI = zeros(256,256,256);
for i = 1:256
    images_recon = SIM_reconstruction(zstack_sheetSI_temp(:,:,Nangle*Nphase*(i-1)+1:Nangle*Nphase*i),size,simafrequency,angles,phi,Nbeam);
    zstackimages_sheetSI(:,:,i) = images_recon(:,:,2);
end

%% besselsheetSI
zstack_besselsheetSI_temp = reshape(permute(xy_image_besselsheetSI, [1 2 4 3]),[N, N, N*Nangle*Nphase]);
zstackimages_besselsheetSI = zeros(256,256,256);
for i = 1:256
    images_recon = SIM_reconstruction(zstack_besselsheetSI_temp(:,:,Nangle*Nphase*(i-1)+1:Nangle*Nphase*i),size,simafrequency,angles,phi,Nbeam);
    zstackimages_besselsheetSI(:,:,i) = images_recon(:,:,2);
end


%% besselsheet2pSI
zstack_besselsheet2pSI_temp = reshape(permute(xy_image_besselsheet2pSI, [1 2 4 3]),[N, N, N*Nangle*Nphase]);
zstackimages_besselsheet2pSI = zeros(256,256,256);
for i = 1:256
    images_recon = SIM_reconstruction(zstack_besselsheet2pSI_temp(:,:,Nangle*Nphase*(i-1)+1:Nangle*Nphase*i),size,simafrequency,angles,phi,Nbeam);
    zstackimages_besselsheet2pSI(:,:,i) = images_recon(:,:,2);
end

    