Commit 5a6cf0cd authored by Zheheng Liu's avatar Zheheng Liu
Browse files

some small fix



Signed-off-by: Zheheng Liu's avatarZheheng Liu <zheheng.liu@esrf.fr>
parent c1fe3073
function wrec = gtMathsWaveletTransformInversePeriodized3D(vol, level, LoR, HiR, conv_mode)
% FUNCTION wdec = gtMathsWaveletTransformInversePeriodized3D(vol, level, LoD, HiD, conv_mode)
% This function is to perform the 3D inverse wavelet transform (IWT).
% INPUT:
% vol : 3D decomposition matrix to reconstruction.
% level : <int> The level of the IWT. The size of 'vol' must be [m,
% n, k] .* (2 ^ level), where m, n, k are integers.
% LoR : Vector of the low-frequency reconstruction filter. Length
% must be even.
% HoR : Vector of the high-frequency reconstruction filter. Length
% must be even.
% conv_mode : {['fft'], 'per'} The method to perform convolution. 'fft'
% is to use the FFT. 'per' is the regular periodic conv.
% OUTPUT:
% wrec : 3D volume reconstructed from WT decompositions.
if (nargin < 5 || isempty(conv_mode))
conv_mode = 'fft';
end
......@@ -98,27 +112,4 @@ function [RecFilters, len_end] = sfPeriodizeFilterWhenLongerThanData(len_f_half,
RecFilters = sum(RecFilters, 2);
RecFilters = reshape(RecFilters, [len_data_half, 4]);
end
end
% if (len_data_half < len_f_half)
% len_end = rem(len_f_half, len_data_half);
% nof_per = floor(len_f_half/len_data_half);
% if len_end
% inds_end = (len_f_half - len_end + 1) : len_f_half;
% RecFilters(1:len_end, :) = RecFilters(1:len_end, :) + RecFilters(inds_end, :);
% RecFilters(inds_end, :) = [];
% else
% len_end = len_data_half;
% end
% if nof_per > 1
% RecFilters = reshape(RecFilters, [len_data_half, nof_per, 4]);
% RecFilters = sum(RecFilters, 2);
% RecFilters = reshape(RecFilters, [len_data_half, 4]);
% end
% len_f_half = len_data_half;
% else
% len_end = len_f_half;
% end
% inds_upsampling = [((len_data - len_end + 2) : len_data), 1:(len_data - len_end + 1)];
% inds_upsampling = reshape(inds_upsampling, 2, len_data_half);
\ No newline at end of file
end
\ No newline at end of file
function wdec = gtMathsWaveletTransformPeriodized3D(vol, level, LoD, HiD, conv_mode)
% FUNCTION wdec = gtMathsWaveletTransformPeriodized3D(vol, level, LoD, HiD, conv_mode)
% This function is to perform the 3D wavelet transform (WT).
% INPUT:
% vol : 3D volume to transform.
% level : <int> The level of the WT. The size of 'vol' must be [m,
% n, k] .* (2 ^ level), where m, n, k are integers.
% LoD : Vector of the low-frequency decomposition filter. Length
% must be even.
% HoD : Vector of the high-frequency decomposition filter. Length
% must be even.
% conv_mode : {['fft'], 'per'} The method to perform convolution. 'fft'
% is to use the FFT. 'per' is the regular periodic conv.
% OUTPUT:
% wdec : 3D matrix containing WT decompositions.
if (nargin < 5 || isempty(conv_mode))
conv_mode = 'fft';
conv_mode = 'fft'; % default is to use FFT for convolution.
end
% reshape the filters to column vectors for convenience.
LoD = LoD(:);
HiD = HiD(:);
% Because of the downsampling in WT, divide the filter into 2 subsets
% to reduce the computation. (so length of filter needs to be even)
DecFilters = [LoD(1:2:end), LoD(2:2:end), HiD(1:2:end), HiD(2:2:end)];
% half filter length
len_f_half = length(DecFilters(:, 1));
% use recursion function for the levels.
wdec = sfWTSingleLevel(vol, level, len_f_half, DecFilters, lower(conv_mode));
end
function vol = sfWTSingleLevel(vol, level, len_f_half, DecFilters, conv_mode)
% size of 3D volume
size_vol = size(vol);
% half of the volume size
size_vol_half = size_vol ./ 2;
% convolution method
switch conv_mode
case 'fft'
% for reshape the filters for each dimension.
% the original size of the matrix containing filters are Nx4.
% It is reshaped to respectively Nx1x1x4, 1xNx1x4 and 1x1xNx4
% for 3 dimensions.
permute_vectors = ...
[1, 3, 4, 2; ...
3, 1, 4, 2; ...
3, 4, 1, 2];
% loop for 3 dimensions
for ii_dim = 1:3
% length of data in current dimension
len_data = size_vol(ii_dim);
% half length of data in current dimension
len_data_half = size_vol_half(ii_dim);
% Adjust filters if they are longer than data. Adjust the
% indices of the data due to the shift of convolution.
[DecFilters_per, ~, inds] = sfAdjustFiltersAndDataInds(len_f_half, len_data, len_data_half, DecFilters);
% To be convenient for changing the indices of
vol_ind = {1:size_vol(1), 1:size_vol(2), 1:size_vol(3)};
vol_ind{ii_dim} = inds(2:2:len_data);
vol1 = vol(vol_ind{1}, vol_ind{2}, vol_ind{3});
vol1 = fft(vol1, len_data_half, ii_dim);
vol_ind{ii_dim} = inds(1:2:(len_data-1));
vol2 = vol(vol_ind{1}, vol_ind{2}, vol_ind{3});
vol1 = fft(vol1, len_data_half, ii_dim);
vol2 = fft(vol2, len_data_half, ii_dim);
DecFilters_per = [DecFilters_per(:, 1) + 1i * DecFilters_per(:, 3), ...
DecFilters_per(:, 2) + 1i * DecFilters_per(:, 4)];
DecFilters_per = permute(DecFilters_per, permute_vectors(ii_dim, :));
......@@ -52,6 +88,7 @@ function vol = sfWTSingleLevel(vol, level, len_f_half, DecFilters, conv_mode)
end
end
% recursion for the levels
if level > 1
vol(1:size_vol_half(1),1:size_vol_half(2),1:size_vol_half(3)) = ...
sfWTSingleLevel(vol(1:size_vol_half(1),1:size_vol_half(2),1:size_vol_half(3)), ...
......
......@@ -493,14 +493,14 @@ function [cl, estim_space_bbox_pix, estim_orient_bbox_rod] = gt6DCreateProjDataF
save(grain_filename, '-struct', 'cl', '-v7.3');
fprintf('\b\b: Done.\n')
fprintf('Saving to sample.mat..')
sample = GtSample.loadFromFile();
cl_info = GtPhase.makeCluster(grs_list, ...
cat(1, samp_ors(:).R_vector), ...
estim_space_bbox_pix, estim_orient_bbox_rod, 2);
sample.phases{phase_id}.setClusterInfo(grs_list, cl_info);
sample.saveToFile();
fprintf('\b\b: Done.\n')
%fprintf('Saving to sample.mat..')
%sample = GtSample.loadFromFile();
%cl_info = GtPhase.makeCluster(grs_list, ...
% cat(1, samp_ors(:).R_vector), ...
% estim_space_bbox_pix, estim_orient_bbox_rod, 2);
%sample.phases{phase_id}.setClusterInfo(grs_list, cl_info);
%sample.saveToFile();
%fprintf('\b\b: Done.\n')
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment