• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # mene a guest Apr 21st, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. %task1heiheihei
2. function A_k = task1(image, k)
3.   %TODO
4.   A = double(imread(image));
5.   [U, S, V] = svd (A);
6.   U = U(:,1:k);
7.   S = S(1:k,1:k);
8.   V = V(:,1:k);
9.   V = V';
10.   A_k = U * S * V;
11. end
12.
13. %task2heiheihei
14.
15. function task2(k,image)
16.    %TODO
17.   A = double(imread(image));
18.   [m n] = size(A);
19.   [U, S, V] = svd (A);
20.   x = diag(S);
21.   s=0;
22.   sort(x,"descend");
23.   subplot(2,2,1);
24.   plot(x)
25.
26.   for i = 1 : k
27.     s = s + S(i,i);
28.     v(i) = s;
29.   endfor
30.   s1 = sum(diag(S));
31.   v = v / s1;
32.   subplot(2,2,2);
33.   plot(v)
34.
35.   for z = 1 : k
36.     A_k = task1(image, z);
37.     s2 = 0;
38.     for i = 1 : m
39.       for j = 1 : n
40.       s2 = s2 + (A(i,j) - A_k(i,j))^2;
41.       endfor
42.   endfor
43.       v1(z) = s2;
44.   endfor
45.   v1 = v1 / (m*n);
46.   subplot(2,2,3);
47.   plot(v1)
48.
49.   for i = 1 : k
50.     qq(i) = (m*i + n*i + i)/(m*n);
51.   endfor
52.   subplot(2,2,4)
53.   plot(qq)
54.
55.   end
56.
57. %task3heiheihei
58.
59. function [A_k S] = task3(image, k)
60.   %TODO
61.   A = double(imread(image));
62.   [m n] = size(A);
63.   for j = 1 : m
64.     u(j) = mean(A(j,:),2);
65.     A(j,:) = A(j,:) - u(j);
66.   endfor
67.   Z = A' / sqrt(n-1);
68.   [U, S, V] = svd(Z);
69.   W = V(:,1:k);
70.   Y = W' * A;
71.   A_k = W * Y + u';
72. endfunction
73.
74.
75. %task4heiheihei
76.
77. function [A_k S] = task4(image, k)
78.    %TODO
79.    A = double(imread(image));
80.   [m n] = size(A);
81.   for j = 1 : m
82.     u(j) = mean(A(j,:),2);
83.     A(j,:) = A(j,:) - u(j);
84.   endfor
85.   Z = 1/(n-1) * A * A';
86.   [V S] = eig(Z);
87.   W = V(:,1:k);
88.   Y = W' * A;
89.   A_k = W * Y + u';
90.  endfunction
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.

Top