Files
cmdla/11-3/readyalefaces_to_tensor.jl

39 lines
1.3 KiB
Julia

using Images, GIFImages
function readyalefaces_to_tensor(str::String="all")::Tuple{Array, Array{String}}
# output (F, descr)
nindividuals = 15
if str == "easy"
extensions = ["happy", "normal", "sad", "sleepy", "surprised", "wink"]
elseif str == "easy-nowink"
extensions = ["happy", "normal", "sad", "sleepy", "surprised"]
elseif str == "nowink"
extensions = ["centerlight", "glasses", "happy", "leftlight", "noglasses", "normal", "rightlight", "sad", "sleepy", "surprised"]
elseif str == "hard" || str == "all"
extensions = ["centerlight", "glasses", "happy", "leftlight", "noglasses", "normal", "rightlight", "sad", "sleepy", "surprised", "wink"]
else
throw(ArgumentError("unknown selector"))
end
F = Array{Float32}(undef, (243, 320, length(extensions), nindividuals))
for i 1:nindividuals
basename = joinpath(@__DIR__, "yalefaces/subject")
if i < 10
basename *= "0" * string(i)
else
basename *= string(i)
end
for j = 1:length(extensions)
fullname = basename * "." * extensions[j] * ".gif"
X = Gray.(gif_decode(fullname))
F[:, :, j, i] = X[:,:,1] # just the first frame of the gif (should have only one in total)
end
end
descr = extensions
(F, descr)
end