📄 get_match.m
字号:
function p = get_match(target, loc_mask, param)
thresh = param.thresh;
gauss = param.gauss(:)';
patches = param.patches;
loc_mask = loc_mask(:)';
target = target(:)';
%Compute the distance between each candidate patch and the target patch,
%weighting pixels using the gaussian, and only considering pixels used
%under a valid mask.
vals = [];
target = target .* loc_mask;
for i = 1:size(patches, 1)
cmp = sum( ((patches(i, :) - target) .* loc_mask).^2 .* gauss );
vals = [vals; [cmp, i]];
end
%Sort the values in order
vals = sortrows(vals, 1);
%Now, iterate over all the candidates, keeping any whose distance is less
%than the threshold, building a distribution on the intensity of the center
%pixel in the candidates
target = patches(vals(1, 2), :);
szh = 1 + (size(patches,2)-1) / 2;
distr = [patches(vals(1, 2), szh)];
for i = 2:size(vals, 1)
if param.fast == 0
distance = sum( ((patches(vals(i, 2), :) - target) .* loc_mask).^2 .* gauss );
else
distance = vals(i,1);
end
if distance <= thresh
distr = [distr, patches(vals(i, 2), szh)];
end
end
%Make sure we have a column vector...
if size(distr,2) > size(distr,1)
distr = distr';
end
%Sample from the generated distribution
ind = ceil(rand(1) * size(distr,1));
p = distr(ind);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -