📄 aux_merge_filters.m
字号:
function f = aux_merge_filters (f1, s1, f2, s2, tag)% FUNCTION f = aux_merge_filters (f1, s1, f2, s2, tag)%% Two filters f1 and f2 (of scale s1 and s2) are combined into one,% and given a new tag. %% More detail: Since the filter structures% are stored in a sparse format, we can not simply concatenate two% different matrices. Although we can "unpack" the filter and then% concatenate, this will not usually be a good method, since 4-D% filters can be huge (many, many features in principle, and that's% why we save filters in sparse format). Thus, we will take some% care in resizing the sparse versions of the filters before% concatenation.s1_tag = ['s' num2str(s1)];s2_tag = ['s' num2str(s2)];% Get the fields from each filter.f1_f1 = getfield(f1, ['f1_' s1_tag]);f1_f2 = getfield(f1, ['f2_' s1_tag]);f1_i1 = getfield(f1, ['i1_' s1_tag]);f1_i2 = getfield(f1, ['i2_' s1_tag]);f1_i3 = getfield(f1, ['i3_' s1_tag]);f1_size = getfield(f1, ['size_' s1_tag]);f1_shift = getfield(f1, ['shift_' s1_tag]);f2_f1 = getfield(f2, ['f1_' s2_tag]);f2_f2 = getfield(f2, ['f2_' s2_tag]);f2_i1 = getfield(f2, ['i1_' s2_tag]);f2_i2 = getfield(f2, ['i2_' s2_tag]);f2_i3 = getfield(f2, ['i3_' s2_tag]);f2_size = getfield(f2, ['size_' s2_tag]);f2_shift = getfield(f2, ['shift_' s2_tag]);% We take the smaller shift size (take the denser sampling).f_shift = min([min(f1_shift) min(f2_shift)]);% f1_size(3) should be equal to f2_size(3), because we assume we% are merging the filters from the same layer (ie. same number of% afferents from the previous layer). In the spatial dimension% (1:2), we take the maximum size.f_size = zeros(1,4);f_size(1:2) = max([f1_size(1:2); f2_size(1:2)]);f_size(3) = f1_size(3);f_size(4) = f1_size(4) + f2_size(4); % number of new featuresf_f1 = put_into_same_size_and_merge (f1_f1, f2_f1, 0);f_f2 = put_into_same_size_and_merge (f1_f2, f2_f2, 0);% Note (0,1,1) -> 0 in sub2ind, so pad_val will be (0,1,1).f_i1 = put_into_same_size_and_merge (f1_i1, f2_i1, 0);f_i2 = put_into_same_size_and_merge (f1_i2, f2_i2, 1);f_i3 = put_into_same_size_and_merge (f1_i3, f2_i3, 1);f = [];f = setfield(f, ['f1_' tag], f_f1);f = setfield(f, ['f2_' tag], f_f2);f = setfield(f, ['i1_' tag], f_i1);f = setfield(f, ['i2_' tag], f_i2);f = setfield(f, ['i3_' tag], f_i3);f = setfield(f, ['size_' tag], f_size);f = setfield(f, ['shift_' tag], f_shift);function y = put_into_same_size_and_merge (x1, x2, pad_val)% FUNCTION y = put_into_same_size_and_merge (x1, x2, pad_val)%% x1 and x2 are both 2-d matrices with different size. We take the% smaller one and put it into the larger size, and pad with pad_val.% Then, we merge along the second dimension.% Resize the smaller matrix.if size(x1,1) > size(x2,1) x2_tmp = ones(size(x1,1), size(x2,2))*pad_val; x2_tmp(1:size(x2,1),:) = x2; x2 = x2_tmp;else x1_tmp = ones(size(x2,1), size(x1,2))*pad_val; x1_tmp(1:size(x1,1),:) = x1; x1 = x1_tmp;end% Merge along the second dimension.y = cat(2, x1, x2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -