📄 comp_mix_scales.m
字号:
function y = comp_mix_scales (x, m, mix_f, type)% FUNCTION y = comp_mix_scales (x, m, mix_f, type)%% We are going to mix scales by (1) resizing two different scales% and (2) concatenating them and (3) using the mex file. For% example, suppose we would like to mix A = [1 1; 1 1] and % B = [2 2 2; 2 2 2; 2 2 2]. (1) Using aux_resize_3d, we resize A% (or fit it to the larger matrix). Now, A = [1 1 1; 1 1 1; 1 1% 1]. (The resizing is done with nearest-neighbor approximation).% (2) Concatenate A and B along the first dimension, so that % x_new = [1 1 1; 1 1 1; 1 1 1; 2 2 2; 2 2 2; 2 2 2]. Scale-mixing% filter will be mx_f = [1; 0; 0; 1]. (3) x_new and mix_f can then% be used with comp_get_next_layer.y = [];x_new = [];% The input m, mixing matrix, will have the same number of scales% as the input, and the scales that are to be mixed will have the% same integer values. In other words, if we want to mix 8 scales% in groups of twos, resulting in 4 scales, % m = [1 1 2 2 3 3 4 4];num_scale = length(m);for i = 1:num_scale scale_tag = ['s' num2str(i)]; old_size(i,:) = size(getfield(x, scale_tag));endfor m_idx = 1:max(m) % loop thru all mixing % find the scales that are to be mixed which_scales = find(m == m_idx); num_s = length(which_scales); % target size new_size = max(old_size(which_scales,:),[],1); % we will mix scales by concatenating all relevant scales (in % which_scales), and then by creating a filter that % corresponds to them. x_tmp = zeros(new_size(1)*num_s, new_size(2), new_size(3)); for i = 1:num_s scale_tag = ['s' num2str(which_scales(i))]; curr_x = getfield(x, scale_tag); curr_x = aux_resize_3d(curr_x, new_size); x_tmp([1:new_size(1)]+(i-1)*new_size(1),:,:) = curr_x; end scale_tag = ['s' num2str(m_idx)]; x_new = setfield(x_new, scale_tag, x_tmp); % The scale-mixing filter was already created in filt_scalemixing % at some arbitrary size, so modify i1_s, according to the % correct size. where_ones = ([1:num_s]-1)*new_size(1)+1; i1_s = repmat([where_ones'; 0], [1 new_size(3)]); siz_s = [max(where_ones) 1 new_size(3) new_size(3)]; mix_f = setfield(mix_f, ['i1_' scale_tag], i1_s); mix_f = setfield(mix_f, ['size_' scale_tag], siz_s); endy = comp_get_next_layer (x_new, mix_f, type);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -