基于CASIA-GaitDatasetB步态图像轮廓数据库的步态周期检测与步态角度特征MATLAB源码
Posted fpga&matlab
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于CASIA-GaitDatasetB步态图像轮廓数据库的步态周期检测与步态角度特征MATLAB源码相关的知识,希望对你有一定的参考价值。
部分核心程序:D197
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 步态特征提取 宽高比特征以及角度特征
close all;
clear;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Trainingfilenum = 3; % 训练人数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for filnum = 1:Trainingfilenum % 第一部分: 从不同文件夹导入图片
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% %%%% %%%% %%%% 第一步: 导入二值化步态图片,图片来自中科院CASIA数据库B库
% 导入图集为一个步态周期,且以步态跨度最大时为起始时刻
figure('NumberTitle','off','Name','数据库图集');
%%%% %%%% 从图集中读取所有图片
fileDir = ['gaitpic\\Trainingset\\cl',num2str(filnum),'\\']; % 文件夹路径(这里指的图片文件)
filePattern = '*.png'; % 文件格式(图片格式)
dis = dir([fileDir,filePattern]); % 利用dir函数,返回fileDir路径下、filePattern
% 所有文件(文件名、文件路径、日期、字节等)
infilenames = dis.name; % 得到文件名
infilenums = length(infilenames); % 得到文件个数
for i=1:infilenums % 循环读取文件
filen = [fileDir infilenamesi]; % '\\gaitpic\\Trainingset\\cl-filnum\\第i个文件'
gpic = imread(filen); % imread('gaitpic\\Trainingset\\cl-filnum\\第i个文件')
GaitMessage(filnum).GaitPicture(:,:,i) = gpic;
imshow(GaitMessage(filnum).GaitPicture(:,:,i));title(['No.1-',num2str(i)]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end % 第一部分 导入图片
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for filnum = 1:Trainingfilenum % 第二部分: 图像预处理
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% %%%% 1、形态学处理
figure('NumberTitle','off','Name','图像预处理-形态学处理');
% picnums获取第filnum个人的步态图片张数
[height,width,picnums] = size( GaitMessage(filnum).GaitPicture);
% 选取形态学处理的结构元素
close_se = strel('disk',4); % 边长为4的圆盘结构元素
open_se = strel('disk',4); % 边长为4的圆盘结构元素
%%%% 进行边长为4的八边形 先闭后开运算
for i=1:picnums % 对该人的所有步态图像进行形态学处理
clo = imclose( GaitMessage(filnum).GaitPicture(:,:,i) ,close_se); % 闭运算操作
ope = imopen(clo,open_se); % 开运算操作
GaitMessage(filnum).Morphology(:,:,i) = ope; % 形态学处理后的图片
imshow( GaitMessage(filnum).Morphology(:,:,i) );title(['No.2-1-',num2str(i)]);
end
%%%% %%%% 2、人像轮廓提取(边缘检测) - 骨骼提取(细化函数) - 生成轮廓骨骼图像
figure('NumberTitle','off','Name','图像预处理-边缘检测');
for i=1:picnums
GaitMessage(filnum).Edgepic(:,:,i) = edge( GaitMessage(filnum).Morphology(:,:,i),'sobel'); % sobel算子
GaitMessage(filnum).Skeletonpic(:,:,i) = bwmorph( GaitMessage(filnum).Morphology(:,:,i),'thin',Inf); % 人体细化
GaitMessage(filnum).EdgeandSkeleton(:,:,i) = GaitMessage(filnum).Edgepic(:,:,i) + GaitMessage(filnum).Skeletonpic(:,:,i); % 生成轮廓骨骼图
% 保存下来,保存路径为:gaitpic/EdgeandSkeleton/all/filnum-es-i.png
imwrite( GaitMessage(filnum).EdgeandSkeleton(:,:,i) , strcat(['gaitpic/EdgeandSkeleton/all/',num2str(filnum),'es',num2str(i),'.png']));
% 画图部分
% imshow( GaitMessage(filnum).Edgepic(:,:,i) );title(['No.2-2-',num2str(i)]); % 显示轮廓图 ;
% imshow( GaitMessage(filnum).Skeletonpic(:,:,i) );title(['No.2-2-',num2str(i)]); % 显示骨骼图
imshow( GaitMessage(filnum).EdgeandSkeleton(:,:,i) );title(['No.2-2-',num2str(i)]); % 显示轮廓骨骼图
% 画图结束
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end % 第二部分: 图像预处理
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for filnum = 1:Trainingfilenum % 第三部分: 步态周期检测与提取
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% picnums获取第filnum个人的步态图片张数
[height,width,picnums] = size( GaitMessage(filnum).GaitPicture);
%%%% %%%% 获得每个轮廓的最小外接矩形 & 以其矩形的长宽作为人像高宽
for i=1:picnums
imbiEdgepic = imbinarize( GaitMessage(filnum).Morphology(:,:,i) ); % 步态图二值化
%%%% regionprops函数用于返回图片的属性,求各个轮廓的最小外接矩形
GaitMessage(filnum).BoundBs(1,i) = regionprops(imbiEdgepic,'BoundingBox'); % 利用函数度量图像区域属性,这里度量最小外接矩形
% 返回一个结构数据,其内是有关最小外接矩形的位置
% 长、宽信息,调用格式:s.BoundingBox
% s.BoundingBox = [x,y,w(△x),h(△y)]
%%%% 求各个对应的宽高比
rec_width = GaitMessage(filnum).BoundBs(i).BoundingBox(3); % 宽
rec_heigh = GaitMessage(filnum).BoundBs(i).BoundingBox(4); % 高
GaitFeatures(filnum).Aspectratio(1,i) = rec_width / rec_heigh; % 宽高比特征
end
% 画图部分:
figure('NumberTitle','off','Name','步态周期检测-宽高比');
plot(GaitFeatures(filnum).Aspectratio); title(['No.3-',num2str(filnum),'步态集-人像宽高比变化曲线']);% 画出面积走势图
% 画图结束
%%%% %%%% 取连续三个局部最小值之间为一个周期(也可以取得连续三个局部最大值之间为一个周期)
%%%% 利用寻找峰值函数找到局部极值
[peas,locs] = findpeaks( -GaitFeatures(filnum).Aspectratio );% 由于想寻找局部极小值,而该函数是寻找局部极大值,所以对其取负
peas = - peas; % 将值还原 % 由于本次未使用这个值,所以注释掉了;如果需要使用,则需要将注释去除,不然值是所需值的负数
%%%% 取连续三个局部最小值之间为一个周期,第一个极小为起点,第三个极小为终点
periodstart = 1;periodend = 3;
GaitMessage(filnum).periodlocs = [locs(periodstart) locs(periodend)];
%%%% 取宽高比周期
GaitMessage(filnum).mPeriod = GaitFeatures(filnum).Aspectratio(GaitMessage(filnum).periodlocs(1):GaitMessage(filnum).periodlocs(2));
% 画图部分:
figure('NumberTitle','off','Name','步态周期检测-周期提取');
plot(GaitMessage(filnum).mPeriod);title(['No.3-',num2str(filnum),'步态集-步态周期内人像宽高比变化曲线']);% 画出面积走势图
% 画图结束
%%%% 取周期内的步态图片
GaitMessage(filnum).GaitPeriod = GaitMessage(filnum).EdgeandSkeleton(:,:,GaitMessage(filnum).periodlocs(1):GaitMessage(filnum).periodlocs(2));
[height,width,picnums] = size( GaitMessage(filnum).GaitPeriod );
for i = 1:picnums
%保存下来,保存路径为:gaitpic/EdgeandSkeleton/period/filnum-es-i.png
imwrite( GaitMessage(filnum).GaitPeriod(:,:,i) , strcat(['gaitpic/EdgeandSkeleton/period/',num2str(filnum),'es',num2str(i),'.png']));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end % 第三部分: 步态周期检测
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for filnum = 1:Trainingfilenum % 第四部分: 角度特征提取
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% %%%% %%%% %%%% 第四步: 步态特征提取
sectornums = 2; % 分区数,即将下半身分为两个分区,将人像以垂直轴(y轴)为分界线,左右分别为一个分区
%%%% %%%% 整个过程角度特征距离特征 以质心为原点,对下半身采用2分区,提取各个分区信息以及轮廓像素信息,
[GaitFeatures(filnum).nthsectorFeatures,Outlinepixelmessage,centroid] = test_Outlinepixel2Centroid_AngleDistance(GaitMessage(filnum).EdgeandSkeleton,sectornums);
% 只获取一个步态周期内的角度特征
for nths = 1:sectornums
GaitFeatures(filnum).nthsectorPeriodFeatures(nths).PeriodaverageAngle = GaitFeatures(filnum).nthsectorFeatures(nths).averageAngle(GaitMessage(filnum).periodlocs(1):GaitMessage(filnum).periodlocs(2));
end
%%%% 画图部分:画出该人步态角度特征
figure('NumberTitle','off','Name','同一人整个过程-角度特征');
for i = 1:sectornums
plot(GaitFeatures(filnum).nthsectorFeatures(i).averageAngle - 270);title(['No.4-',num2str(filnum),'-1','同一人的1/2分区-角度均值变化曲线']) % 画出角度走势图
hold on
end
% 对应的周期角度特征曲线
figure('NumberTitle','off','Name','同一人步态周期内-角度特征');
for i = 1:sectornums
plot(GaitFeatures(filnum).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270);title(['No.4-',num2str(filnum),'-2','同一人的1/2分区-周期角度均值变化曲线']) % 画出角度走势图
hold on
end
%%%% 画图结束
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end % 第四部分: 角度特征提取
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for filnum = 1:Trainingfilenum % 画图部分-画出当前所有测试人员的角度特征曲线
% 注:这里给出最多画10人不同曲线的代码,由于曲线线条形状、颜色不同,采用switch语句来画
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% %%%% 画图部分: 画出当前所有测试人员的角度特征曲线
switch filnum
case 1
figure('NumberTitle','off','Name','所有人整个过程-角度特征');
title('不同行人左右分区角度特征比较');% 画出走势图
for i = 1:sectornums
plot(GaitFeatures(1).nthsectorFeatures(i).averageAngle - 270,'b-o','MarkerFaceColor','b');
hold on
end
case 2
for i = 1:sectornums
plot(GaitFeatures(2).nthsectorFeatures(i).averageAngle - 270,'g-x','MarkerFaceColor','g');
hold on
end
case 3
for i = 1:sectornums
plot(GaitFeatures(3).nthsectorFeatures(i).averageAngle - 270,'r-*','MarkerFaceColor','r');
hold on
end
case 4
for i = 1:sectornums
plot(GaitFeatures(4).nthsectorFeatures(i).averageAngle - 270,'c-p','MarkerFaceColor','c');
hold on
end
case 5
for i = 1:sectornums
title('不同行人左右分区角度特征比较');% 画出走势图
plot(GaitFeatures(5).nthsectorFeatures(i).averageAngle - 270,'k-s','MarkerFaceColor','k');
hold on
end
case 6
figure('NumberTitle','off','Name','步态角度特征');
title('不同行人左右分区角度特征比较');% 画出走势图
for i = 1:sectornums
plot(GaitFeatures(6).nthsectorFeatures(i).averageAngle - 270,'b-o','MarkerFaceColor','b');
hold on
end
case 7
for i = 1:sectornums
plot(GaitFeatures(7).nthsectorFeatures(i).averageAngle - 270,'g-x','MarkerFaceColor','g');
hold on
end
case 8
for i = 1:sectornums
plot(GaitFeatures(8).nthsectorFeatures(i).averageAngle - 270,'r-*','MarkerFaceColor','r');
hold on
end
case 9
for i = 1:sectornums
plot(GaitFeatures(9).nthsectorFeatures(i).averageAngle - 270,'c-p','MarkerFaceColor','c');
hold on
end
case 10
for i = 1:sectornums
title('不同行人左右分区角度特征比较');% 画出走势图
plot(GaitFeatures(10).nthsectorFeatures(i).averageAngle - 270,'k-s','MarkerFaceColor','k');
hold on
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end % 画图部分结束-画出当前所有测试人员的角度特征曲线
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for filnum = 1:Trainingfilenum % 画图部分-画出当前所有测试人员的角度特征曲线
% 注:这里给出最多画10人不同曲线的代码,由于曲线线条形状、颜色不同,采用switch语句来画
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% %%%% 对应的周期角度特征曲线
switch filnum
case 1
figure('NumberTitle','off','Name','不同行人步态周期内角度特征');
title('不同行人左右分区角度特征比较');% 画出走势图
for i = 1:sectornums
plot(GaitFeatures(1).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'b-o','MarkerFaceColor','b');
hold on
end
case 2
for i = 1:sectornums
plot(GaitFeatures(2).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'g-x','MarkerFaceColor','g');
hold on
end
case 3
for i = 1:sectornums
plot(GaitFeatures(3).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'r-*','MarkerFaceColor','r');
hold on
end
case 4
for i = 1:sectornums
plot(GaitFeatures(4).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'c-p','MarkerFaceColor','c');
hold on
end
case 5
for i = 1:sectornums
title('不同行人左右分区角度特征比较');% 画出走势图
plot(GaitFeatures(5).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'k-s','MarkerFaceColor','k');
hold on
end
case 6
figure('NumberTitle','off','Name','步态角度特征');
title('不同行人左右分区角度特征比较');% 画出走势图
for i = 1:sectornums
plot(GaitFeatures(6).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'b-o','MarkerFaceColor','b');
hold on
end
case 7
for i = 1:sectornums
plot(GaitFeatures(7).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'g-x','MarkerFaceColor','g');
hold on
end
case 8
for i = 1:sectornums
plot(GaitFeatures(8).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'r-*','MarkerFaceColor','r');
hold on
end
case 9
for i = 1:sectornums
plot(GaitFeatures(9).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'c-p','MarkerFaceColor','c');
hold on
end
case 10
for i = 1:sectornums
title('不同行人左右分区角度特征比较');% 画出走势图
plot(GaitFeatures(10).nthsectorPeriodFeatures(i).PeriodaverageAngle - 270,'k-s','MarkerFaceColor','k');
hold on
end
end
%%%% %%%% 画图结束
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end % 画图部分结束-画出当前所有测试人员的角度特征曲线
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
以上是关于基于CASIA-GaitDatasetB步态图像轮廓数据库的步态周期检测与步态角度特征MATLAB源码的主要内容,如果未能解决你的问题,请参考以下文章
步态识别基于深度学习的步态识别系统的MATLAB仿真,包括ALEXNET,改进CNN,GOOGLENET