• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 6th, 2016 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2.
3. % img = noise(50+100*gaussf(rr>85,2),'gaussian',20)
4. img = zeros(250);
5. img(:,1:end/2) = 1;
6. img = noise(50+100*gaussf(img,2),'gaussian',20)
7.
8. s = zeros(60,2);
9. s(:,2) = 1;
10. s(1,2) = 50;
11. s = cumsum(s);
12. s(:,1) = 160;
13.
14. x = s(:,1);
15. y = s(:,2);
16. % x = 120+50*cos(0:0.1:2*pi)';
17. % y = 140+60*sin(0:0.1:2*pi)';
18. hold on, plot([x;x(1)],[y;y(1)],'g')
19.
20. alpha = 0.001;
21. beta = 0.4;
22. gamma = 100;
23. iterations = 50;
24.
25. N = length(x);
26. a = gamma*(2*alpha+6*beta)+1;
27. b = gamma*(-alpha-4*beta);
28. c = gamma*beta;
29.
30. P = diag(repmat(a,1,N));
31. P = P + diag(repmat(b,1,N-1), 1) + diag(   b, -N+1);
32. P = P + diag(repmat(b,1,N-1),-1) + diag(   b,  N-1);
33. P = P + diag(repmat(c,1,N-2), 2) + diag([c,c],-N+2);
34. P = P + diag(repmat(c,1,N-2),-2) + diag([c,c], N-2);
35. %
36.
37. d = gamma * (-alpha);
38. e = gamma * (2*alpha);
39.
40. P(1:2,:) = 0;
41. P(1,1) = -gamma;
42. P(2,1) = d;
43. P(2,2) = e;
44. P(2,3) = d;
45.
46. P(N-1:N,:) = 0;
47. P(N-1,N-2) = d;
48. P(N-1,N-1) = e;
49. P(N-1,N) = d;
50. P(N,N) = -gamma;
51.
52. P = inv(P);
54.
55. for ii = 1:iterations
56.    % Calculate external force
57.    coords = [x,y];
58.    fex = get_subpixel(f{1},coords,'linear');
59.    fey = get_subpixel(f{2},coords,'linear');
60.    % Move control points
61.    x = P*(x+gamma*fex);
62.    y = P*(y+gamma*fey);
63. %    if mod(ii,5)==0
64.       plot([x;x(1)],[y;y(1)],'b')
65. %    end
66. end
67. plot([x;x(1)],[y;y(1)],'r')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?