clear
close all
clc
input_dir = 'D:\PROJECT M.Tech\Databases\001\001\bg-01\090';
filenames = dir(fullfile(input_dir, '*.png'));
tot_ims1 = numel(filenames);
for n = 1:tot_ims1
filename = fullfile(input_dir, filenames(n).name);
img1_p1 = imread(filename);
img1_p1 = bwareaopen(img1_p1,50);
se = strel('square',5);
s_im= imdilate(img1_p1, se);
s_im= imclose(s_im, se);
% Label the 2 levels thresholded image
[LabeledImage, Num]=bwlabel(s_im);
% Calculate the area of different components in LabeledImage2
STATS = regionprops(s_im, 'Area');
% Get the label of the biggest area in LabeledImage. This will be the human
[MaxArea,MaxAreaLabel]=max([STATS(:).Area]);
% Binary detected breast region
BinaryRegion=LabeledImage==MaxAreaLabel;
labeledImage = bwconncomp(BinaryRegion,8);
measurements = regionprops(labeledImage,'BoundingBox','Centroid');
bb = measurements.BoundingBox;
bco = measurements.Centroid;
AR(n)= bb(4)/bb(3);
end
fgs=5;
subplot( fgs,1, 1)
plot(AR, '-o')
title('aspect ratio')
%Normalization of aspect ration followed by mean filtering
subplot( fgs,1, 2)
mean_sub= AR- mean(AR);
std_div= mean_sub/std(mean_sub);
smooth_wave= smooth(std_div, 17, 'moving');
plot( smooth_wave )
title('smoothed')
% * autocorrelation signals
subplot(fgs,1, 3)
autoc= xcorr(smooth_wave);
plot( autoc )
title('autoc')
% * first-order derivative signals of autocorrelations
% * Peak positions indicating the periods.
subplot(fgs,1, 4)
df= diff(autoc);
plot( autoc )
[PKS, LOCS]= findpeaks(df);
hold on
plot(LOCS, PKS, 'ro')
title('deriv')
Distance_Peaks = (max(diff(LOCS))+ mean(diff(LOCS)))/2;
gait_period= round(Distance_Peaks)