function best_match = best_match_pattern(target, SAMPLE_POOL, dist_func)global_definitions;min_dist = 1.0000e+100;s = block_size*block_size*source.dim;mask = reshape((target ~= 0), 1, s);best_match = zeros(size(target));for i=1:number_of_samples dist = dist_func(reshape(target, 1, s), reshape(SAMPLE_POOL(i).data, 1, s).*mask); if dist < min_dist best_match = SAMPLE_POOL(i).data; best_match_number = i; min_dist = dist; endendfprintf('patch number %d is the best choice, MSE: %d\n', best_match_number, sqrt(min_dist/s));end