Question: Write a python code. Please modify it using my code. I want to make a test image by selecting 50 of the following eigenfaces with

Write a python code. Please modify it using my code.

I want to make a test image by selecting 50 of the following eigenfaces with large eigenvalue.

Apply SVD to the covariance matrix

And collect 10 different cropped face images.

Represent each face images using the eigenfaces

Compare the coefficients {c1,c2,...,cn} for face recognition.

Find the Coeffiencts

- inner product of eigenface vector and test face image vector.(eigenfaces -> orthonormal)

Generate face image using eigenfaces.

linear combination of eigenface vectors adding the mean vector.

Write a python code. Please modify it using my code. I wantto make a test image by selecting 50 of the following eigenfaceswith large eigenvalue. Apply SVD to the covariance matrix And collect 10

different cropped face images. Represent each face images using the eigenfaces Comparethe coefficients {c1,c2,...,cn} for face recognition. Find the Coeffiencts - inner product

13 4. Test face recognition Collect 10 different cropped face images > 5 test images for one face Represent each face images using the eigenfaces Compare the coefficients {C1, C2, "., Cn} for face recognition - M=C te2 +C3 ...ten Mean vector of collected face images 0000, 14 Find the Coefficients inner product of eigenface vector and test face image vector Eigenfaces => orthonormal - M=C1 +c2 +C3 ...te Ck = -M 00000 (inner product of e, and test face image vector) 15 Generate face image using eigenfaces linear combination of eigenface vectors adding the mean vector T 2C1 +0 |t0 ...ten +M In [66]; import numpy as np import matplot lib.pyplot as plt from PIL import Image %matplot lib inline In [67]: f94 = ['9332898' '9338446', '9338497', '9338519', '9414649' '9416994', 'ajflem', 'ajsega', 'anonym', 'anonyml', 'anpage', 'asamma', 'asheal', 'astefa', 'cchris', 'cgboyc', 'cicarr', 'cj sake'. cmkirk', 'cshubb', dakram', dcbowe', 'drbost', 'ekavaz', 'gj hero', 'gmwate', 'gsreas', 'jabins', 'irtobi', 'klclar', Tejnno' 'martin', 'mberdo', 'mdpove', 'mefait', 'michael', 'mjhans' 'namull, 'ndhagu', 'njmoor, 'npmitc' 'nrclar', 'obeidn', 'phughe', 'ptnich', 'rgspru', 'rilabr', 'ropwil', 'robin', 'rrowle', 'rsanti', 'saedwa', 'sandm', 'sidick', 'sj beck', 'sbirc', 'spletc', 'svkriz', 'tony', 'voudcx'] In [71]: base = [1 mage.open( f'C:/faces94(1)/{p}/{p}, {i}.jpg').convert('L') for i in range(1,21) for p in f94] M = len(base) X = np.array([base[i].get data() for i in range(M)]) print (X[0:50] ) mean = np.mean(X, 0) phi = X mean [[164 165 168 .. [187 188 189 (172 172 172 ... 9 & 7 79 87 92] 94 94 94 [ 75 75 75 57 57 57] [ 70 71 71 223 217 213] [ 99 101 102 ... 153 143 147]] In [72] : e_faces, sigma, v = np. linalg.svd(phi . transpose(), full_matrices=False) weights = [np.dot (X[i]-mean, e_faces) for i in range(M)] np. shape(weights) Out [72] : (1200, 1200) In [74]: K - 50 recon = mean + np. dot (weights[X, 0:50), e_faces[:, 0:50].1) TypeError Traceback (most recent call last) in 1 k = 50 ----> 2 recon = mean + np. dot (weights[X, 0:50], e_faces. I) 3 TypeError: list indices must be integers or slices, not tuple 13 4. Test face recognition Collect 10 different cropped face images > 5 test images for one face Represent each face images using the eigenfaces Compare the coefficients {C1, C2, "., Cn} for face recognition - M=C te2 +C3 ...ten Mean vector of collected face images 0000, 14 Find the Coefficients inner product of eigenface vector and test face image vector Eigenfaces => orthonormal - M=C1 +c2 +C3 ...te Ck = -M 00000 (inner product of e, and test face image vector) 15 Generate face image using eigenfaces linear combination of eigenface vectors adding the mean vector T 2C1 +0 |t0 ...ten +M In [66]; import numpy as np import matplot lib.pyplot as plt from PIL import Image %matplot lib inline In [67]: f94 = ['9332898' '9338446', '9338497', '9338519', '9414649' '9416994', 'ajflem', 'ajsega', 'anonym', 'anonyml', 'anpage', 'asamma', 'asheal', 'astefa', 'cchris', 'cgboyc', 'cicarr', 'cj sake'. cmkirk', 'cshubb', dakram', dcbowe', 'drbost', 'ekavaz', 'gj hero', 'gmwate', 'gsreas', 'jabins', 'irtobi', 'klclar', Tejnno' 'martin', 'mberdo', 'mdpove', 'mefait', 'michael', 'mjhans' 'namull, 'ndhagu', 'njmoor, 'npmitc' 'nrclar', 'obeidn', 'phughe', 'ptnich', 'rgspru', 'rilabr', 'ropwil', 'robin', 'rrowle', 'rsanti', 'saedwa', 'sandm', 'sidick', 'sj beck', 'sbirc', 'spletc', 'svkriz', 'tony', 'voudcx'] In [71]: base = [1 mage.open( f'C:/faces94(1)/{p}/{p}, {i}.jpg').convert('L') for i in range(1,21) for p in f94] M = len(base) X = np.array([base[i].get data() for i in range(M)]) print (X[0:50] ) mean = np.mean(X, 0) phi = X mean [[164 165 168 .. [187 188 189 (172 172 172 ... 9 & 7 79 87 92] 94 94 94 [ 75 75 75 57 57 57] [ 70 71 71 223 217 213] [ 99 101 102 ... 153 143 147]] In [72] : e_faces, sigma, v = np. linalg.svd(phi . transpose(), full_matrices=False) weights = [np.dot (X[i]-mean, e_faces) for i in range(M)] np. shape(weights) Out [72] : (1200, 1200) In [74]: K - 50 recon = mean + np. dot (weights[X, 0:50), e_faces[:, 0:50].1) TypeError Traceback (most recent call last) in 1 k = 50 ----> 2 recon = mean + np. dot (weights[X, 0:50], e_faces. I) 3 TypeError: list indices must be integers or slices, not tuple

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!