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

📄 learn_snapshots.m

📁 Standard model object recognition matlab code
💻 M
字号:
function [f1,f2] = learn_snapshots (X,patch_siz,num_patch,num_afferents)% FUNCTION [f1,f2] = learn_snapshots (X,patch_siz,num_patch,num_afferents)%% Take num_patch snapshots of object X, which is a 3-D matrix.  These% snapshots have the dimensions of patch_siz (in the first two% dimensions of X) and the num_afferents number of afferents.global ON_CON;[maxY, maxX, num_feat] = size(X);f1 = [];f2 = [];% Get patchesPatchSiz = max(patch_siz);if ((maxX-PatchSiz) < 0 | (maxY-PatchSiz) < 0)  disp('Image is too small for learning patches: Skip image.');else  tot_pos  = (maxX-PatchSiz+1)*(maxY-PatchSiz+1);  for k = 1:length(patch_siz)    rand_pos = randperm(tot_pos);    if (num_patch > tot_pos)      disp(['Max number of patches (' num2str(tot_pos) ') exceeded']);      nPatch = tot_pos;    else      nPatch = num_patch;    end    for l = 1:nPatch      [y, x]    = ind2sub([maxY-PatchSiz+1 maxX-PatchSiz+1], rand_pos(l));      feat      = X(y:y+PatchSiz-1, x:x+PatchSiz-1, :);      tot_pos2  = patch_siz(k)*patch_siz(k)*num_feat;      rand_pos2 = randperm(tot_pos2);      mask      = zeros([size(feat)]);      norm      = 0;      for p = 1:num_afferents	indx      = [patch_siz(k) patch_siz(k) num_feat];	[y2,x2,f] = ind2sub(indx, rand_pos2(p));	% Since we may want to keep zero weight, we have a global	% variable ON_CON that specifies the "on connections".	% Any weights that are greater than ON_CON will be known	% to be the valid weight.  (Although f2 would also act as	% ON_CON identifier...)	mask(y2,x2,f) = ON_CON;	norm          = norm + feat(y2,x2,f);      end      if norm > 0.01  % if the patch is not blank.	% hence the total number of features may be smaller than nPatch.	f1 = cat(4, f1, feat+mask);	f2 = cat(4, f2, mask == ON_CON);      end          end  endend

⌨️ 快捷键说明

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