Lesson 8/11 and fixed spelling error in prev lesson
This commit is contained in:
31
11-8/interactiverec.jl
Normal file
31
11-8/interactiverec.jl
Normal file
@ -0,0 +1,31 @@
|
||||
using LinearAlgebra, Plots, Statistics
|
||||
|
||||
include("../11-3/readyalefaces_to_tensor.jl")
|
||||
function interactiverec(F, iterstop::Union{Nothing, Integer}=nothing)
|
||||
# given a 243x320 image F, displays it as sum of components
|
||||
stdsize = (243, 320)
|
||||
|
||||
(X, _) = readyalefaces_to_tensor()
|
||||
|
||||
X = reshape(X, (prod(stdsize), Integer(prod(size(X)) / prod(stdsize))))
|
||||
|
||||
avg = mean(X, dims=2)
|
||||
Xs = X .- avg
|
||||
(U,S,V) = svd(X)
|
||||
|
||||
h = Plots.heatmap(reshape(avg, stdsize), yflip=true)
|
||||
display(h)
|
||||
|
||||
if iterstop == nothing
|
||||
upto = size(U, 2)
|
||||
else
|
||||
upto = min(size(U, 2), iterstop)
|
||||
end
|
||||
|
||||
# no fancy slider, not enough time
|
||||
for d ∈ 0:upto
|
||||
h = heatmap(reshape(avg .+ U[:, 1:d] * U[:, 1:d]' * F, stdsize), yflip=true)
|
||||
IJulia.clear_output(true)
|
||||
display(h)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user