image processing - MATLAB Computing distance from a point to a set of points -


consider matrix a:

a = magic(5)  17    24     1     8    15 23     5     7    14    16  4     6    13    20    22 10    12    19    21     3 11    18    25     2     9 

i have compute following formula: w_ij = ||i(i) - i(j)|| ^ 2 point a(1,1) neighborhood i.e. a(1:2, 1:2). don't understand formula stand since not specified. euclidean distance?

i tried

norm(a(1, 1) - a(1:2, 1:2)) 

but gives me scalar. i'm expecting vector of 4 elements. can me?

you can see formula in context on page 4 of http://www.cs.berkeley.edu/~malik/papers/sm-ncut.pdf (equation 11). in paper use f intensity assume have i. since intensities scalars, want take square of differences.

you want calculate weight matrix calculates affinity of entry in other entry in a. because has 25 entries, weight matrix 25x25.

since worried brightness easy:

len = length(a(:)); w = zeros(len); = 1:len     j = 1:len        w(i,j) = (a(i) - a(j))^2;     end end 

now if want weight between a(1,1) , a(1,2) can this:

i = sub2ind(size(a), 1, 1) j = sub2ind(size(a), 1, 2) w(i, j) 

but if set r=1 (according ncuts formula) might want this:

sigma= 10; r = 1; = magic(3); siz = size(a); len = length(a(:)); w = zeros(len); = 1:len     j = 1:len        [xi,yi] = ind2sub(siz,i);        [xj,yj] = ind2sub(siz,j);        if((xi-xj)^2 + (yi-yj)^2) > r^2            w(i,j) = 0;        else            w(i,j) = exp(-(a(i) - a(j))^2 / sigma^2);        end     end end  a11 = sub2ind(siz, 1, 1) a12 = sub2ind(siz, 1, 2) w(a11, a12) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -