Regarding non local weight computation

1 view (last 30 days)
Smitha A
Smitha A on 7 Nov 2019
Hello all,
I am trying to implement Non local methods of image processing. I want to find the dissimilarity between patches in an image. I found this code online.
Can anyone please help me to understand this code? I understand that in an image of say 100x100, with window size of 5x5 and patch size of 3x3, there will be altogether (25, 10000) distance measures. (10000 windows and 25 patches in each window) But how is the patch and window being constructed in this program ?
Is there any simpler/ faster way in Matlab to implement non local distance computation?
[m, n] = size(f); % f is the input image of size m x n.
r = m*n;
G = fspecial('gaussian', [40, 40], sigma);
% Computing distance
dist = zeros((2*ws+1)*(2*ws+1), r);
padu = padarray(f,[ws ws],'symmetric','both');
for i = -ws:ws
for j = -ws:ws
shiftpadu = padarray(f,[ws-i ws-j],'symmetric','pre');
shiftpadu = padarray(shiftpadu,[ws+i ws+j],'symmetric','post');
tempu = (padu-shiftpadu);
tempu = tempu(1+ws:m+ws, 1+ws:n+ws);% tempu(r,c) = f(r,c) - f(r+i,c+j);
padtempu = padarray(tempu,[ps,ps],'symmetric','both');
uu = conv2(padtempu.^2, G, 'same');
uu = uu(1+ps:m+ps, 1+ps:n+ps);
k=(j+ws)*(2*ws+1)+i+ws+1;
dist(k, :) = reshape(uu, 1, []);
end
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!