Files
cmdla/Lessons/11-08/eigenfaces_scatter.jl

32 lines
1.0 KiB
Julia
Raw Normal View History

using Colors, LinearAlgebra, Plots, Statistics
function eigenfaces_scatter(images, indices)
(w, h, nExpressions, nIndividuals) = size(images)
X= reshape(images, (w*h, nIndividuals*nExpressions))
avg = mean(X, dims=2)
Xd = X .- avg
(U,S,V) = svd(Xd)
scores = U[:,indices]' * Xd
# normalize scores and samples
# scores = bsxfun(@rdivide,scores,sqrt(sum(abs(scores).^2)));
if length(indices) == 3
scatter(
scores[1,:],
scores[2,:],
scores[3,:],
markersize = 3*ones(size(scores[1,:])),
marker_z = reshape(kron(1:nExpressions, ones(1,nIndividuals)'), (nExpressions*nIndividuals, 1)),
legend = nothing
)
elseif length(indices) == 2
scatter(
scores[1,:],
scores[2,:],
markersize = 3*ones(size(scores[1,:])),
marker_z = reshape(kron(1:nExpressions, ones(1,nIndividuals)'), (nExpressions*nIndividuals, 1)),
legend = nothing
)
end
end