mirror of
https://github.com/c-sooyoung/fold_slice.git
synced 2026-09-17 23:59:11 +09:00
initial commit
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
% tomo_filtered = filter_x(tomo_filtered,freq_scale)
|
||||
% Receives a tomogram and applies filtering only along the third index of
|
||||
% a 3D matrix.
|
||||
% Inputs:
|
||||
% tomo Input tomogram matrix
|
||||
% freq_scale Frequency cutoff
|
||||
% Manuel Guizar Feb 14, 2016
|
||||
|
||||
%*-----------------------------------------------------------------------*
|
||||
%| |
|
||||
%| Except where otherwise noted, this work is licensed under a |
|
||||
%| Creative Commons Attribution-NonCommercial-ShareAlike 4.0 |
|
||||
%| International (CC BY-NC-SA 4.0) license. |
|
||||
%| |
|
||||
%| Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch) |
|
||||
%| |
|
||||
%| Author: CXS group, PSI |
|
||||
%*-----------------------------------------------------------------------*
|
||||
% You may use this code with the following provisions:
|
||||
%
|
||||
% If the code is fully or partially redistributed, or rewritten in another
|
||||
% computing language this notice should be included in the redistribution.
|
||||
%
|
||||
% If this code, or subfunctions or parts of it, is used for research in a
|
||||
% publication or if it is fully or partially rewritten for another
|
||||
% computing language the authors and institution should be acknowledged
|
||||
% in written form in the publication: “Data processing was carried out
|
||||
% using the “cSAXS matlab package” developed by the CXS group,
|
||||
% Paul Scherrer Institut, Switzerland.”
|
||||
% Variations on the latter text can be incorporated upon discussion with
|
||||
% the CXS group if needed to more specifically reflect the use of the package
|
||||
% for the published work.
|
||||
%
|
||||
% A publication that focuses on describing features, or parameters, that
|
||||
% are already existing in the code should be first discussed with the
|
||||
% authors.
|
||||
%
|
||||
% This code and subroutines are part of a continuous development, they
|
||||
% are provided “as they are” without guarantees or liability on part
|
||||
% of PSI or the authors. It is the user responsibility to ensure its
|
||||
% proper use and the correctness of the results.
|
||||
|
||||
|
||||
function tomo_filtered = filter_x(tomo_filtered,freq_scale)
|
||||
|
||||
|
||||
%%% Filter a tomogram along the last index %%%
|
||||
% freq_scale = 0.1;
|
||||
%
|
||||
% %%% Create example %%%
|
||||
% N = 200;
|
||||
% tomo_filtered = zeros([N N N]);
|
||||
% for ii = 1:N
|
||||
% tomo_filtered(ii,:,:) = phantom(N);
|
||||
% end
|
||||
% tomo_filtered = repmat(tomo_filtered,[1 1 N]);
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%% Create filter %%%
|
||||
|
||||
Nfilt = size(tomo_filtered,2);
|
||||
|
||||
filt = zeros([Nfilt 1]);
|
||||
d = freq_scale;
|
||||
|
||||
w = [-Nfilt/2:Nfilt/2-1]+mod(Nfilt/2,2);
|
||||
w = 2*pi*w/Nfilt;
|
||||
|
||||
filt = (1+cos(w/d)) / 2;
|
||||
filt(abs(w)/d>pi) = 0;
|
||||
filt = ifftshift(filt);
|
||||
|
||||
% figure(1);
|
||||
% plot(filt);
|
||||
%%%%%%
|
||||
%
|
||||
|
||||
filt3D = repmat(reshape(filt,[1,Nfilt,1]),[size(tomo_filtered,1) 1 size(tomo_filtered,3)]);
|
||||
|
||||
tomo_filtered = real(ifft( fft(tomo_filtered,[],2).*filt3D ,[],2));
|
||||
|
||||
|
||||
|
||||
% %% Image %%%
|
||||
% figure(1)
|
||||
% imagesc(squeeze(tomo_filtered(2,:,:)));
|
||||
% % imagesc(squeeze(filt3D(1,:,:)));
|
||||
% colorbar
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
% tomo_filtered = filter_y(tomo,freq_scale)
|
||||
% Receives a tomogram and applies filtering only along the third index of
|
||||
% a 3D matrix.
|
||||
% Inputs:
|
||||
% tomo Input tomogram matrix
|
||||
% freq_scale Frequency cutoff
|
||||
% Manuel Guizar Feb 14, 2016
|
||||
|
||||
|
||||
%*-----------------------------------------------------------------------*
|
||||
%| |
|
||||
%| Except where otherwise noted, this work is licensed under a |
|
||||
%| Creative Commons Attribution-NonCommercial-ShareAlike 4.0 |
|
||||
%| International (CC BY-NC-SA 4.0) license. |
|
||||
%| |
|
||||
%| Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch) |
|
||||
%| |
|
||||
%| Author: CXS group, PSI |
|
||||
%*-----------------------------------------------------------------------*
|
||||
% You may use this code with the following provisions:
|
||||
%
|
||||
% If the code is fully or partially redistributed, or rewritten in another
|
||||
% computing language this notice should be included in the redistribution.
|
||||
%
|
||||
% If this code, or subfunctions or parts of it, is used for research in a
|
||||
% publication or if it is fully or partially rewritten for another
|
||||
% computing language the authors and institution should be acknowledged
|
||||
% in written form in the publication: “Data processing was carried out
|
||||
% using the “cSAXS matlab package” developed by the CXS group,
|
||||
% Paul Scherrer Institut, Switzerland.”
|
||||
% Variations on the latter text can be incorporated upon discussion with
|
||||
% the CXS group if needed to more specifically reflect the use of the package
|
||||
% for the published work.
|
||||
%
|
||||
% A publication that focuses on describing features, or parameters, that
|
||||
% are already existing in the code should be first discussed with the
|
||||
% authors.
|
||||
%
|
||||
% This code and subroutines are part of a continuous development, they
|
||||
% are provided “as they are” without guarantees or liability on part
|
||||
% of PSI or the authors. It is the user responsibility to ensure its
|
||||
% proper use and the correctness of the results.
|
||||
|
||||
|
||||
function tomo_filtered = filter_y(tomo_filtered,freq_scale)
|
||||
|
||||
|
||||
%%% Filter a tomogram along the last index %%%
|
||||
% freq_scale = 0.1;
|
||||
%
|
||||
% %%% Create example %%%
|
||||
% N = 200;
|
||||
% tomo_filtered = zeros([N N N]);
|
||||
% for ii = 1:N
|
||||
% tomo_filtered(ii,:,:) = phantom(N);
|
||||
% end
|
||||
% tomo_filtered = repmat(tomo_filtered,[1 1 N]);
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%% Create filter %%%
|
||||
|
||||
Nfilt = size(tomo_filtered,3);
|
||||
|
||||
filt = zeros([Nfilt 1]);
|
||||
d = freq_scale;
|
||||
|
||||
w = [-Nfilt/2:Nfilt/2-1]+mod(Nfilt/2,2);
|
||||
w = 2*pi*w/Nfilt;
|
||||
|
||||
filt = (1+cos(w/d)) / 2;
|
||||
filt(abs(w)/d>pi) = 0;
|
||||
filt = ifftshift(filt);
|
||||
|
||||
% figure(1);
|
||||
% plot(filt);
|
||||
%%%%%%
|
||||
%
|
||||
|
||||
filt3D = repmat(reshape(filt,[1,1,Nfilt]),[size(tomo_filtered,1) size(tomo_filtered,2) 1]);
|
||||
|
||||
tomo_filtered = real(ifft( fft(tomo_filtered,[],3).*filt3D ,[],3));
|
||||
|
||||
|
||||
|
||||
% %% Image %%%
|
||||
% figure(1)
|
||||
% imagesc(squeeze(tomo_filtered(2,:,:)));
|
||||
% % imagesc(squeeze(filt3D(1,:,:)));
|
||||
% colorbar
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
% tomo_filtered = filter_y(tomo,freq_scale)
|
||||
% Receives a tomogram and applies filtering only along the third index of
|
||||
% a 3D matrix.
|
||||
% Inputs:
|
||||
% tomo Input tomogram matrix
|
||||
% freq_scale Frequency cutoff
|
||||
% Manuel Guizar Feb 14, 2016
|
||||
|
||||
|
||||
%*-----------------------------------------------------------------------*
|
||||
%| |
|
||||
%| Except where otherwise noted, this work is licensed under a |
|
||||
%| Creative Commons Attribution-NonCommercial-ShareAlike 4.0 |
|
||||
%| International (CC BY-NC-SA 4.0) license. |
|
||||
%| |
|
||||
%| Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch) |
|
||||
%| |
|
||||
%| Author: CXS group, PSI |
|
||||
%*-----------------------------------------------------------------------*
|
||||
% You may use this code with the following provisions:
|
||||
%
|
||||
% If the code is fully or partially redistributed, or rewritten in another
|
||||
% computing language this notice should be included in the redistribution.
|
||||
%
|
||||
% If this code, or subfunctions or parts of it, is used for research in a
|
||||
% publication or if it is fully or partially rewritten for another
|
||||
% computing language the authors and institution should be acknowledged
|
||||
% in written form in the publication: “Data processing was carried out
|
||||
% using the “cSAXS matlab package” developed by the CXS group,
|
||||
% Paul Scherrer Institut, Switzerland.”
|
||||
% Variations on the latter text can be incorporated upon discussion with
|
||||
% the CXS group if needed to more specifically reflect the use of the package
|
||||
% for the published work.
|
||||
%
|
||||
% A publication that focuses on describing features, or parameters, that
|
||||
% are already existing in the code should be first discussed with the
|
||||
% authors.
|
||||
%
|
||||
% This code and subroutines are part of a continuous development, they
|
||||
% are provided “as they are” without guarantees or liability on part
|
||||
% of PSI or the authors. It is the user responsibility to ensure its
|
||||
% proper use and the correctness of the results.
|
||||
|
||||
|
||||
function tomo_filtered = filter_z(tomo_filtered,freq_scale)
|
||||
|
||||
|
||||
%%% Filter a tomogram along the last index %%%
|
||||
% freq_scale = 0.1;
|
||||
%
|
||||
% %%% Create example %%%
|
||||
% N = 200;
|
||||
% tomo_filtered = zeros([N N N]);
|
||||
% for ii = 1:N
|
||||
% tomo_filtered(ii,:,:) = phantom(N);
|
||||
% end
|
||||
% tomo_filtered = repmat(tomo_filtered,[1 1 N]);
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%% Create filter %%%
|
||||
|
||||
Nfilt = size(tomo_filtered,1);
|
||||
|
||||
filt = zeros([Nfilt 1]);
|
||||
d = freq_scale;
|
||||
|
||||
w = [-Nfilt/2:Nfilt/2-1]+mod(Nfilt/2,2);
|
||||
w = 2*pi*w/Nfilt;
|
||||
|
||||
filt = (1+cos(w/d)) / 2;
|
||||
filt(abs(w)/d>pi) = 0;
|
||||
filt = ifftshift(filt);
|
||||
|
||||
% figure(1);
|
||||
% plot(filt);
|
||||
%%%%%%
|
||||
%
|
||||
|
||||
filt3D = repmat(reshape(filt,[Nfilt,1,1]),[1 size(tomo_filtered,2) size(tomo_filtered,3)]);
|
||||
|
||||
tomo_filtered = real(ifft( fft(tomo_filtered,[],1).*filt3D ,[],1));
|
||||
|
||||
|
||||
|
||||
% %% Image %%%
|
||||
% figure(1)
|
||||
% imagesc(squeeze(tomo_filtered(2,:,:)));
|
||||
% % imagesc(squeeze(filt3D(1,:,:)));
|
||||
% colorbar
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
% FUNCTION [ sub_thetaT sub_ind_T] = split_tomogram( indices, theta, num_sub_tomograms )
|
||||
% Divides up the tomogram into sub tomograms according to the matrix
|
||||
% indices.
|
||||
% A combined tomogram is in each row. The single tomograms contained in each
|
||||
% row are given in the columns.
|
||||
% For example, four sub tomograms out of 8 with a pairing of 1 2 , 3 4 etc
|
||||
% would be given by indices = [[1 2];[3 4];[5 6];[7 8]]
|
||||
% All of the first 4 sub tomograms will be returned by indices = [[1] [2] [3] [4]]
|
||||
% The output are cells.
|
||||
|
||||
%*-----------------------------------------------------------------------*
|
||||
%| |
|
||||
%| Except where otherwise noted, this work is licensed under a |
|
||||
%| Creative Commons Attribution-NonCommercial-ShareAlike 4.0 |
|
||||
%| International (CC BY-NC-SA 4.0) license. |
|
||||
%| |
|
||||
%| Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch) |
|
||||
%| |
|
||||
%| Author: CXS group, PSI |
|
||||
%*-----------------------------------------------------------------------*
|
||||
% You may use this code with the following provisions:
|
||||
%
|
||||
% If the code is fully or partially redistributed, or rewritten in another
|
||||
% computing language this notice should be included in the redistribution.
|
||||
%
|
||||
% If this code, or subfunctions or parts of it, is used for research in a
|
||||
% publication or if it is fully or partially rewritten for another
|
||||
% computing language the authors and institution should be acknowledged
|
||||
% in written form in the publication: “Data processing was carried out
|
||||
% using the “cSAXS matlab package” developed by the CXS group,
|
||||
% Paul Scherrer Institut, Switzerland.”
|
||||
% Variations on the latter text can be incorporated upon discussion with
|
||||
% the CXS group if needed to more specifically reflect the use of the package
|
||||
% for the published work.
|
||||
%
|
||||
% A publication that focuses on describing features, or parameters, that
|
||||
% are already existing in the code should be first discussed with the
|
||||
% authors.
|
||||
%
|
||||
% This code and subroutines are part of a continuous development, they
|
||||
% are provided “as they are” without guarantees or liability on part
|
||||
% of PSI or the authors. It is the user responsibility to ensure its
|
||||
% proper use and the correctness of the results.
|
||||
|
||||
|
||||
function [ sub_thetaT sub_ind_T] = split_tomogram( indices, theta, num_sub_tomograms )
|
||||
|
||||
[sortedTheta, ind] = sort(theta);
|
||||
|
||||
%% no_subtomos = 16
|
||||
n = log2(num_sub_tomograms);
|
||||
if mod(n,1) > 0.000001
|
||||
disp(['Error - impossible number of subtomograms chosen'])
|
||||
subtomo_order = NaN;
|
||||
return
|
||||
end
|
||||
subtomos = zeros(1,num_sub_tomograms);
|
||||
k= 1;
|
||||
jj=1;
|
||||
k_prev = k;
|
||||
for i=1:n
|
||||
|
||||
k = k_prev/2;
|
||||
while k <= 1
|
||||
jj = jj+1;
|
||||
subtomos(jj)=k;
|
||||
k=k+k_prev;
|
||||
end
|
||||
k_prev = k_prev/2;
|
||||
end
|
||||
[dump,subtomo_order]= sort(subtomos);
|
||||
|
||||
|
||||
%%
|
||||
|
||||
subtomo_order = [1 5 3 7 2 6 4 8];
|
||||
|
||||
|
||||
for i = 1: num_sub_tomograms;
|
||||
sub_theta_u{i} = sortedTheta(subtomo_order(i):num_sub_tomograms:end);
|
||||
sub_ind_u{i} = ind(subtomo_order(i):num_sub_tomograms:end);
|
||||
end
|
||||
|
||||
for i = 1 : size(indices,1);
|
||||
Combined_Angle = [sub_theta_u{indices(i,1:end)}];
|
||||
Combined_Index = [sub_ind_u{indices(i,1:end)}];
|
||||
Combined = sortrows(transpose([ Combined_Index ; Combined_Angle ]),2);
|
||||
sub_ind_T{i} = Combined(:,1);
|
||||
if std(diff(Combined(:,2)))/mean(diff(Combined(:,2))) > 0.03
|
||||
disp(['Combined sub tomogram ', num2str(i), ' has too large deviations in the angles. The sub tomograms are probably not equally spaced'])
|
||||
end
|
||||
% std(diff(Combined(:,2)))/mean(diff(Combined(:,2)))
|
||||
sub_thetaT{i} = Combined(:,2);
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user