Answered step by step
Verified Expert Solution
Question
1 Approved Answer
solve q 4 for me and the code is: import numpy as np from matplotlib.image import imread import matplotlib.pyplot as plt #load image def load
solve q for me and the code is: import numpy as np
from matplotlib.image import imread
import matplotlib.pyplot as plt
#load image
def loadimagefilepathBackgroundCAU.jpg:
imageraw imreadfilepath
# Displaying an image in grayscale.
imagesum imageraw.sumaxis
X imagesumimagesum.max #treat X as a D x N matrix treat each column as a sample and each row as a feature
Xmean npmeanX axis keepdimsTrue
pltfigurefigsize
pltimshowX cmappltcmgray
plttitleOriginal Image', fontsize
pltshow
pltclose
return X Xmean
# compute covariance matrix
def computecovmatX Xmean:
### Fill in ################################
covmat
############################################
return covmat
if namemain:
X Xmean loadimageBackgroundCAU.jpg
covmat computecovmatX Xmean
eigenvalues eigenvectors nplinalg.eighcovmat
### sort from highest to lowest eigenvalues
eigenvectors eigenvectors: npargsorteigenvalues
eigenvalues eigenvaluesnpargsorteigenvalues
### Compute the projectoin matrix B B B B B
### Fill in ################################
B
B
B
B
B
############################################
### Reconstructe image: make Xtilde using B B B B B
### Don't forget PCA is performed on the meanshifted image. So you have to add the mean after reconstruction!
### Fill in ################################
Xtilde
Xtilde
Xtilde
Xtilde
Xtilde
############################################
for K in :
pltfigurefigsize
if K :
pltimshowXtilde cmappltcmgray
elif K :
pltimshowXtilde cmappltcmgray
elif K :
pltimshowXtilde cmappltcmgray
elif K :
pltimshowXtilde cmappltcmgray
elif K :
pltimshowXtilde cmappltcmgray
plttitleReconstructed Image KformatK fontsize
pltshow
pltclose
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