YaleFace人脸数据集包含丰富的人脸数据,包含各种光照条件,在深度学习的人脸识别和光度立体三维重建中应用广泛。数据集参考链接如下:
- Yale-Face-database
- ExtYaleDatabase
原文件为.info和.pgm格式,需要读取转换格式。
P00: 是人脸的标号;
A-30: A是azimuth,即方位角,所对应的数值为-30°;
E+40: E是elevation,即仰角,所对应的数值为+40°。
方位角、天顶角、仰角的关系如下图所示:
仰角为天顶角的余角。通过方位角和天顶角描述方向向量参考该篇
设 仰 角 e l e v a t i o n 记 为 θ l ; 方 位 角 a z i m u t h 记 为 φ l 设仰角elevation记为 \theta_l; \\ 方位角azimuth记为\varphi_l 设仰角elevation记为θl;方位角azimuth记为φl
不难得到光源方向L的表达式:
L ⃗ = ( cos θ l cos φ l , cos θ l sin φ l , sin θ l ) \vec{L}=\left(\cos \theta_{l} \cos \varphi_{l}, \cos\theta_{l} \sin \varphi_{l}, \sin\theta_{l}\right) L=(cosθlcosφl,cosθlsinφl,sinθl)
现利用matlab读取数据转存到mat格式:
clc
close all
clear all
datapath = './yaleB12/';
dstpath = './yaleB12_mat/';
type = '*.info';
if(~exist(dstpath))
mkdir(dstpath)
end
infolists = dir([datapath type]);
infonums = length(infolists);
for info_id = 1:infonums
infoname = infolists(info_id).name;
infodatas = importdata([datapath infoname]);
lens = length(infodatas); % 直接对文件夹下.pgm进行检索也可
imglists_480_640 = []; % 480*640为实际图像大小,保存到imglists中会转换为列向量
lightlists = [];
for img_id = 1:lens
imgname = infodatas{img_id};
if(~startsWith(imgname,'yaleB'))
continue
end
if contains(imgname,'Amb')
imgAmb = importdata([datapath imgname]);
imglists_480_640 = [imglists_480_640,imgAmb(:)];
continue
end
imgface = importdata([datapath imgname]);
azimuth = str2double(imgname(13:16));
elevation = str2double(imgname(18:20));
lightdirection = Genlightvector(elevation,azimuth);
imglists_480_640 = [imglists_480_640,imgface(:)];
lightlists = [lightlists;lightdirection];
end
save([dstpath strrep(infoname,'info','mat')],"imglists_480_640","lightlists")
end
function lightvector = Genlightvector(elevation,azimuth)
lightvector = [cosd(azimuth) * cosd(elevation) sind(azimuth) * cosd(elevation) sind(elevation)];
end
读取保存的mat文件,可以查看图像信息:
clc
close all
clear all
datapath = './yaleB11_mat/';
type = '*.mat';
matlists = dir([datapath type]);
matnums = length(matlists);
for i = 1:matnums
imglists_480_640 = load([datapath matlists(i).name]).imglists_480_640;
lightlists = load([datapath matlists(i).name]).lightlists;
imgnums = size(imglists_480_640,2);
img_step = 4;
nums = imgnums / img_step;
for j = 1:nums
figure
for img_id = 1:img_step
imgface = imglists_480_640(:,img_step * (j - 1) + img_id);
imgface = reshape(imgface,480,640);
subplot(2,2,img_id)
imshow(imgface)
end
pause(1)
end
end