Adds plots
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 196 KiB |
After Width: | Height: | Size: 176 KiB |
After Width: | Height: | Size: 183 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 184 KiB |
After Width: | Height: | Size: 182 KiB |
After Width: | Height: | Size: 181 KiB |
|
@ -42,7 +42,6 @@ def one_d() -> None:
|
||||||
U, S, VT, _ = uz_image.compute_PCA(points)
|
U, S, VT, _ = uz_image.compute_PCA(points)
|
||||||
|
|
||||||
uz_image.plot_histogram_pca(U, S, VT)
|
uz_image.plot_histogram_pca(U, S, VT)
|
||||||
|
|
||||||
# U is the matrix of eigenvectors
|
# U is the matrix of eigenvectors
|
||||||
# S is the vector of eigenvalues
|
# S is the vector of eigenvalues
|
||||||
|
|
||||||
|
@ -234,21 +233,24 @@ def three_b():
|
||||||
|
|
||||||
img2 = imgs[0].copy()
|
img2 = imgs[0].copy()
|
||||||
|
|
||||||
# Project image into PCA subspace
|
fig, axs = plt.subplots(5, 2)
|
||||||
y_i = np.matmul(img2 - mean, U)
|
for i in range(5):
|
||||||
y_i[0] = 0
|
|
||||||
|
# Project image into PCA subspace
|
||||||
|
y_i = np.matmul(img2 - mean, U)
|
||||||
|
y_i[i] = 0
|
||||||
|
|
||||||
# Project image back into original subspace
|
# Project image back into original subspace
|
||||||
x_i = np.matmul(y_i, U.T) + mean
|
x_i = np.matmul(y_i, U.T) + mean
|
||||||
|
|
||||||
# Plot the original image and the projected images
|
# Plot the original image and the projected images
|
||||||
diff = (np.sum(np.abs(img - x_i)))
|
diff = (np.sum(np.abs(img - x_i)))
|
||||||
fig, axs = plt.subplots(1, 2)
|
|
||||||
fig.suptitle(f'Add noise in PCA space, diff: {np.round(diff, 2)}')
|
axs[i, 0].imshow(img2.reshape((96, 84)).copy(), cmap='gray')
|
||||||
axs[0].imshow(img2.reshape((96, 84)), cmap='gray')
|
axs[i, 1].imshow(x_i.reshape((96, 84)).copy(), cmap='gray')
|
||||||
axs[1].imshow(x_i.reshape((96, 84)), cmap='gray')
|
|
||||||
|
axs[i, 1].set(title=f'Add noise in PCA space y[{i}], diff: {np.round(diff, 2)}')
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
def three_c():
|
def three_c():
|
||||||
"""
|
"""
|
||||||
Effect of the number of components on the reconstruction: Take a random
|
Effect of the number of components on the reconstruction: Take a random
|
||||||
|
@ -430,7 +432,7 @@ def main():
|
||||||
#one_f()
|
#one_f()
|
||||||
#two_b()
|
#two_b()
|
||||||
#three_a()
|
#three_a()
|
||||||
#three_b()
|
three_b()
|
||||||
#three_c()
|
#three_c()
|
||||||
#three_d()
|
#three_d()
|
||||||
#three_e()
|
#three_e()
|
||||||
|
|