For an array of points given by x and y, this function quite elegantly and efficiently returns indices of each point's nearest neighbor like this:
ipdm([x y],'subset','nearestneighbor','result','struct');
Takes ~5 seconds to solve for 15,000 points on my laptop. That's quite fast.

5

13 May 2014

Active contour platform
Compare the performance of different level sets and active contours methods.

Wolfgang,
Thanks for this awesome submission. It was very helpful. I however have a questions..
On line 165 you perform the following operation
edges(end) = inf;
Can you explain the logic behind it?
The reason that I ask it that when the data is uniformly distributed in space the number of data pairs separated by a lag (h) decreases as h increases.
However, as written line 165 then makes later lines (l78 and 179)
S.val = accumarray(ixedge,...
lam,[numel(edges) 1],fvar,nan);
S.num = accumarray(ixedge,ones(size(lam))...
,[numel(edges) 1],@sum,nan);
Calculate the gamma value and the number of pairs using the the rest of the data set. You then do a final modification of the arrays but that does eliminate the extra data poins used int he Variogram calculation..
Let me give you an example.
My edges vector before line 165
250 500 750 1000 1250 1500 1750 2000 2250 2500 2750 3000
My edges vector after line 165
250 500 750 1000 1250 1500 1750 2000 2250 2500 2750 Inf
Then on lines
178,179 and 186, 187
you produce the S.distance,S.num and S.val struct arrays
This is what the S.distance says:
625
875
1125
1375
1625
1875
2125
2375
2625
2875
Then this is what the S.num says:
41
40
39
38
37
36
35
34
33
32
31
59
You see That 59 should not be there there are no 59 number of data pairs with an average lag distance of 2875. In fact there are only 30.
If I comment line 165 then I get the expected result of monotonically decreasing number of pairs as lag distance increases.
Let me know what you think...
Carlos Soto