diff options
Diffstat (limited to 'doc/source/user/plot_approx.py')
-rw-r--r-- | doc/source/user/plot_approx.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/source/user/plot_approx.py b/doc/source/user/plot_approx.py new file mode 100644 index 000000000..a2d6981d9 --- /dev/null +++ b/doc/source/user/plot_approx.py @@ -0,0 +1,19 @@ +from scipy import misc +import matplotlib.pyplot as plt +import numpy as np +from numpy import linalg + +img = misc.face() +img_array = img / 255 +img_gray = img_array @ [0.2126, 0.7152, 0.0722] + +U, s, Vt = linalg.svd(img_gray) + +Sigma = np.zeros((768, 1024)) +for i in range(768): + Sigma[i, i] = s[i] + +k = 10 + +approx = U @ Sigma[:, :k] @ Vt[:k, :] +plt.imshow(approx, cmap="gray") |