The Extended Yale Face Database B 转为 Matlab 格式

前言

网上找了一个小的人脸识别数据库,没有找到mat格式的,可以直接用,花了一点时间自己将图像导入matlab里面,顺便将过程分享一下

下载链接

裁剪后的官网下载链接
http://vision.ucsd.edu/extyaleb/CroppedYaleBZip/CroppedYale.zip

百度网盘附带mat格式的文件
https://pan.baidu.com/s/1QVIWvyuQuMpCtcBeigpLmg
提取码:pzjr

提取过程

将CroppedYale.zip解压后的目录,作为matlab的当前目录
里面包含了38个目录,一个目录代表一个人,每个目录下大约有64张,大小为192x168。ambient为背景图,不进行提取。将每一个人存储为一个cell,每个cell包含一个矩阵,每张图进行线性化,作为矩阵的一列

clear;clc;
dirroot = pwd();
DIRS=dir(dirroot);
n=length(DIRS);
cnt = 1;
X = [];
for i=1:n
   if DIRS(i).isdir
      if DIRS(i).name=="." ||  DIRS(i).name==".."
          continue;
      end
      DIRS(i).name
      X{cnt} = LoadDirectory(sprintf('%s\\%s',dirroot,DIRS(i).name));
      cnt = cnt +1;
   end
end

LoadDirectory的代码

function [X] = LoadDirectory(dirroot)
DIRS=dir(sprintf('%s\\*.pgm',dirroot));
n=length(DIRS);
X = [];
cnt = 1;
for i=1:n
    if ~DIRS(i).isdir
        k = strfind(DIRS(i).name,'Ambient');
        if isempty(k)
            DIRS(i).name
            I = imread(sprintf('%s\\%s',dirroot,DIRS(i).name));
            I = reshape(I,[],1);
            X(:,cnt) = I;
            cnt = cnt + 1;
        end
    end
end

测试

Data = X{38};
[m,n] = size(Data);
k = ceil(sqrt(n));
a = 1/k;
b = 1/k;
for i = 1:1:n
    %subplot(k,k,i)显示图像效果太差,因此自定义子图大小的位置
    subplot('Position',[floor((i-1)/k)*a mod(i-1,k)*b  a b]);   
    img = uint8(Data(:,i));
    img = reshape(img,192,168);
    imshow(img);
end

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值