⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aux_replicate_filters.m

📁 Standard model object recognition matlab code
💻 M
字号:
function f_out = aux_replicate_filters (f,num_scale_full,num_features)% FUNCTION f_out = aux_replicate_filters (f,num_scale_full,num_features)%% The filter, f, may have only a few scales, so here, we merge all% into one scale, and then replicate it to multiple scales% (num_scale_full).  This function is used, for example, (1) to% learn S2 features in a few scales, but replicate in all scales,% and (2) to create 2x2 or nxn artifitial features (as in HMAX),% but replicate in all scales.% The arguement "num_features"  determines how many features to% take, since there may be very many learned features.f_tmp = merge_filters (f,num_features);f_out = replicate_filters (f_tmp,num_scale_full);function f_out = merge_filters (f,num_features)% FUNCTION f_out = merge_filters (f,num_features)%% Here we merge all features in different scales into one scale% (s1).  We use aux_merge_filters function.scales = aux_get_filt_info(fieldnames(f));% Merge all features in different scales.f_out = [];if length(scales) > 1  % Put everything with 's1' (scale = 1) tag.  f_out = aux_merge_filters (f, scales(1), f, scales(2), 's1');  if length(scales) > 2 % merge rest of scales    for i = 3:length(scales)      f_out = aux_merge_filters (f_out, 1, f, scales(i), 's1');    end  endelse % only one scale in f  s_tag = ['_s' num2str(scales(1))];  f_out = setfield(f_out, 'f1_s1', getfield(f, ['f1' s_tag]));  f_out = setfield(f_out, 'f2_s1', getfield(f, ['f2' s_tag]));  f_out = setfield(f_out, 'i1_s1', getfield(f, ['i1' s_tag]));  f_out = setfield(f_out, 'i2_s1', getfield(f, ['i2' s_tag]));  f_out = setfield(f_out, 'i3_s1', getfield(f, ['i3' s_tag]));  f_out = setfield(f_out, 'size_s1', getfield(f, ['size' s_tag]));  f_out = setfield(f_out, 'shift_s1', getfield(f, ['shift' s_tag]));end% Now get the merged fields.f_f1 = getfield(f_out, 'f1_s1');f_f2 = getfield(f_out, 'f2_s1');f_i1 = getfield(f_out, 'i1_s1');f_i2 = getfield(f_out, 'i2_s1');f_i3 = getfield(f_out, 'i3_s1');f_size = getfield(f_out, 'size_s1');% There can be quite a large number of features, so take the% specified number of features.  If you want to take the random% features, you will have to randomize the input f, in the first% place.  Since we probably want to use the same features over and% over again, we do NOT extract random features here.if num_features <= f_size(4)  which_features = [1:num_features];  f_size(4) = num_features;else   % There are not that many features, so pick all features.  which_features = [1:f_size(4)];  disp('Requested too many features.');endf_out = setfield(f_out, 'f1_s1', f_f1(:,which_features));f_out = setfield(f_out, 'f2_s1', f_f2(:,which_features));f_out = setfield(f_out, 'i1_s1', f_i1(:,which_features));f_out = setfield(f_out, 'i2_s1', f_i2(:,which_features));f_out = setfield(f_out, 'i3_s1', f_i3(:,which_features));f_out = setfield(f_out, 'size_s1', f_size);function f_out = replicate_filters (f, num_scale_full)% FUNCTION f_out = replicate_filters (f, num_scale_full)%% Replicate filter f in all scale (1 through num_scale_full).  % In the previous function (merge_filters), all filters are put% into "s1" scale.%f_f1 = getfield(f, 'f1_s1');%f_f2 = getfield(f, 'f2_s1');%f_i1 = getfield(f, 'i1_s1');%f_i2 = getfield(f, 'i2_s1');%f_i3 = getfield(f, 'i3_s1');% It is a waste of memory to copy and store all the same filters.% Therefore, a blank field is stored in the first scale 's1', and in% comp_get_next_layer, we see if the filters in the higher scale are [].f_f1 = [];f_f2 = [];f_i1 = [];f_i2 = [];f_i3 = [];f_size = getfield(f, 'size_s1');f_shift = getfield(f, 'shift_s1');f_out = f;for i = 2:num_scale_full   scale_tag = ['s' num2str(i)];  f_out = setfield(f_out, ['f1_' scale_tag], f_f1);  f_out = setfield(f_out, ['f2_' scale_tag], f_f2);  f_out = setfield(f_out, ['i1_' scale_tag], f_i1);  f_out = setfield(f_out, ['i2_' scale_tag], f_i2);  f_out = setfield(f_out, ['i3_' scale_tag], f_i3);  f_out = setfield(f_out, ['size_' scale_tag], f_size);  f_out = setfield(f_out, ['shift_' scale_tag], f_shift);end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -