https://github.com/MrDragon1/OmnidirectionImageIntrinsicDecomposition
Raw File
Tip revision: 57fa9f3ae2c3a3539c592e37c09f18d0e8be5c2e authored by MrDragon1 on 23 February 2024, 11:48:25 UTC
update example images (fig7&8)
Tip revision: 57fa9f3
NonLocalConstraint_KNN.m
function [As] = NonLocalConstraint_KNN(I,normal,point, nn_num_s ,shadow)
    run('utils\vlfeat-0.9.21/toolbox/vl_setup.m');
    [h,w,~] = size(I);
    I = reshape(I,h*w,3);
    normal = reshape(normal,h*w,3);
    points_whitened=reshape(whiten(reshape(point,[],3)),size(I));%whiten the 3D points
    points_whitened = points_whitened./max(max(points_whitened));
    n = h*w;
   
    data=[reshape(points_whitened,[],3) normal]';
    [ind,dis]=(vl_kdtreequery(vl_kdtreebuild(data),data,data,'numneighbors',nn_num_s));
    ind = double(ind);
    dis = dis(:);
    tmp=[reshape(repmat(1:n,[nn_num_s 1]),[],1) reshape(ind,[],1)];
    tmp = unique([min(tmp(:,1),tmp(:,2)) max(tmp(:,1),tmp(:,2))],'rows');
    diff = shadow;
    point_tmp = diff(:);
    edge1 = point_tmp(tmp(:,1));
    edge2 = point_tmp(tmp(:,2));
    diff = (edge1 - edge2);
    diff = sum(diff.^2, 2);

    h_pos = h / 2 - mod(tmp,h);
    h_height = abs(sin(h_pos(:,1)/h * pi)) + abs(sin(h_pos(:,2)/h*pi));

    weightAs = ones(size(diff)).*(abs(diff) < 0.05) .* exp(0.5 *h_height);
    edgeS = tmp;

    weightAs = weightAs(:);
    As = sparse(edgeS(:,1), edgeS(:,1), weightAs, h*w, h*w)...
       - sparse(edgeS(:,1), edgeS(:,2), weightAs, h*w, h*w)...
       + sparse(edgeS(:,2), edgeS(:,2), weightAs, h*w, h*w)...
       - sparse(edgeS(:,2), edgeS(:,1), weightAs, h*w, h*w);
end
back to top