Question
import numpy as np import matplotlib.pyplot as plt from PIL import Image import cv2 %matplotlib inline images = ['9332898', '9338446', '9338497', '9338519', '9414649', '9416994', 'ajflem',
import numpy as np import matplotlib.pyplot as plt from PIL import Image import cv2 %matplotlib inline
images = ['9332898', '9338446', '9338497', '9338519', '9414649', '9416994', 'ajflem', 'ajsega', 'anonym', 'anonym1', 'anpage', 'asamma', 'asheal', 'astefa', 'cchris', 'cgboyc', 'cjcarr', 'cjsake', 'cmkirk', 'cshubb', 'dakram', 'dcbowe', 'drbost', 'ekavaz', 'gjhero', 'gmwate', 'gsreas', 'jabins', 'jrtobi', 'klclar', 'lejnno', 'martin', 'mberdo', 'mdpove', 'mefait', 'michael', 'mjhans', 'namull', 'ndhagu', 'njmoor', 'npmitc', 'nrclar', 'obeidn', 'phughe', 'ptnich', 'rgspru', 'rjlabr', 'rnpwil', 'robin', 'rrowle', 'rsanti', 'saedwa', 'sandm', 'sidick', 'sjbeck', 'slbirc', 'spletc', 'svkriz', 'tony', 'voudcx']
base = [Image.open(f'C:/face images/{p}/{p}.{i}.jpg').convert('L') for i in range(1,21) for p in images]
F = np.array([base[i].getdata() for i in range(M)])
mean = np.mean(F, 0)
A = F - mean
--------------------------------
Write down the code that represents the mean face image and the code that reconstructs the face.
I got a dataset and a code from this page, but it's not working.
https://wellecks.wordpress.com/tag/eigenfaces/
https://share.cocalc.com/share/4af510406b461ba71cce183927d6725652a63341/eigenfaces.ipynb?viewer=share
# weights is an n xn matrix weights = numpy.dot (ma_data, e_faces) For each image, we have a weight for each of the n eigenfaces, so weights is an n x n matrix. To reconstruct a face, we dot the face's weights (a row in the weights matrix) with the transpose of the eigenfaces (n xp matrix), and add the mean face back in: # reconstruct the face located at img_idx recon = mu + numpy.dot(weights[img_idx, :], e_faces.T) recon = mean + np. dot (weights[F, :], eigenfaces. T) TypeError Traceback (most recent call last)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started