-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YangLiu
authored
Apr 6, 2021
1 parent
5d5406e
commit 149adec
Showing
10 changed files
with
1,218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function [GADF_image] = GADF(signal) | ||
%Compute the Gramian Angular Field of a signal | ||
% signal is the original signal, GASF_image is the Gramian Summation Angular Field of the signal | ||
% Min-Max scaling | ||
min_signal=min(signal); | ||
max_signal=max(signal); | ||
scaled_signal=(2*signal-max_signal-min_signal)/(max_signal-min_signal); | ||
% Floating point inaccuracy! | ||
for i=1:length(scaled_signal) | ||
if(scaled_signal(i)>=1) | ||
scaled_signal(i)=1; | ||
else | ||
scaled_signal(i)=scaled_signal(i); | ||
end | ||
if(scaled_signal(i)<=-1) | ||
scaled_signal(i)=-1; | ||
else | ||
scaled_signal(i)=scaled_signal(i); | ||
end | ||
end | ||
% Polar encoding | ||
phi_signal=asin(scaled_signal); | ||
r=linspace(0,1,length(scaled_signal)); | ||
% GADF Computation (every term of the matrix) | ||
GADF_image=zeros(length(scaled_signal),length(scaled_signal)); | ||
for m=1:length(scaled_signal) | ||
for n=1:length(scaled_signal) | ||
GADF_image(m,n)=sin(phi_signal(m)-phi_signal(n)); | ||
end | ||
end | ||
|
||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function [GASF_image] = GASF(signal) | ||
%Compute the Gramian Angular Field of a signal | ||
%signal is the original signal, GASF_image is the Gramian Summation Angular Field of the signal | ||
% Min-Max scaling | ||
min_signal=min(signal); | ||
max_signal=max(signal); | ||
scaled_signal=(2*signal-max_signal-min_signal)/(max_signal-min_signal); | ||
% Floating point inaccuracy! | ||
for i=1:length(scaled_signal) | ||
if(scaled_signal(i)>=1) | ||
scaled_signal(i)=1; | ||
else | ||
scaled_signal(i)=scaled_signal(i); | ||
end | ||
if(scaled_signal(i)<=-1) | ||
scaled_signal(i)=-1; | ||
else | ||
scaled_signal(i)=scaled_signal(i); | ||
end | ||
end | ||
% Polar encoding | ||
phi_signal=acos(scaled_signal); | ||
r=linspace(0,1,length(scaled_signal)); | ||
% GASF Computation (every term of the matrix) | ||
GASF_image=zeros(length(scaled_signal),length(scaled_signal)); | ||
for m=1:length(scaled_signal) | ||
for n=1:length(scaled_signal) | ||
GASF_image(m,n)=cos(phi_signal(m)+phi_signal(n)); | ||
end | ||
end | ||
|
||
end | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
%Gramian Summation Angular Field and Gramian Difference Angular Field | ||
clc; | ||
clear; | ||
clear all; | ||
load('a10_s1_t1_inertial.mat'); | ||
ax = d_iner(:,6);%1-6 | ||
% GADF_ax=GADF(ax'); | ||
% imshow(mat2gray(GADF_ax)); | ||
|
||
GASF_ax=GASF(ax'); | ||
imshow(mat2gray(GASF_ax)); | ||
% ay = iner(:,2); | ||
% az = iner(:,3); | ||
|
||
% gx = iner(:,4); | ||
% gy = iner(:,5); | ||
% gz = iner(:,6); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
%Calculate the GAF inages in UTD-MHAD dataset | ||
clc; | ||
clear; | ||
clear all; | ||
GASF_or_GADF='GASF'; | ||
Inertial_path='E:\Berkeley MHAD\Accelerometer\Shimmer06\'; | ||
Inertial_GAF_path='E:\Berkeley MHAD\Accelerometer\Shimmer06_GAF\'; | ||
Inertial_data_dir = dir(Inertial_path); | ||
foldername = {Inertial_data_dir(:).name}; | ||
Inertial_data_dir = setdiff(foldername,{'.','..'}); | ||
if ~exist([Inertial_GAF_path],'dir') | ||
mkdir([Inertial_GAF_path]); | ||
end | ||
for i=1:length(Inertial_data_dir) | ||
|
||
path=cell2mat(Inertial_data_dir(i)); | ||
Inertial_data=load([Inertial_path,path]); | ||
path=path(1:end-4); | ||
%if ~exist([Inertial_GAF_path,path],'dir') | ||
% mkdir([Inertial_GAF_path,path]); | ||
%end | ||
if GASF_or_GADF=='GASF' | ||
ax = Inertial_data(:,1); | ||
GASF_ax=GASF(ax'); | ||
ay = Inertial_data(:,2); | ||
GASF_ay=GASF(ay'); | ||
az = Inertial_data(:,3); | ||
GASF_az=GASF(az'); | ||
GASF_a=zeros(size(GASF_ax,1),size(GASF_ax,2),3); | ||
GASF_a(:,:,1)=mat2gray(GASF_ax); | ||
GASF_a(:,:,2)=mat2gray(GASF_ay); | ||
GASF_a(:,:,3)=mat2gray(GASF_az); | ||
imwrite(GASF_a,[Inertial_GAF_path,path,'_GASF_a.jpg']); | ||
|
||
else if GASF_or_GADF=='GADF' | ||
ax = Inertial_data.d_iner(:,1); | ||
GADF_ax=GADF(ax'); | ||
ay = Inertial_data.d_iner(:,2); | ||
GADF_ay=GADF(ay'); | ||
az = Inertial_data.d_iner(:,3); | ||
GADF_az=GADF(az'); | ||
GADF_a=zeros(size(GADF_ax,1),size(GADF_ax,2),3); | ||
GADF_a(:,:,1)=mat2gray(GADF_ax); | ||
GADF_a(:,:,2)=mat2gray(GADF_ay); | ||
GADF_a(:,:,3)=mat2gray(GADF_az); | ||
imwrite(GADF_a,[Inertial_GAF_path,path,'_GADF_a.jpg']); | ||
|
||
gx = Inertial_data.d_iner(:,4); | ||
GADF_gx=GADF(gx'); | ||
gy = Inertial_data.d_iner(:,5); | ||
GADF_gy=GADF(gy'); | ||
gz = Inertial_data.d_iner(:,6); | ||
GADF_gz=GADF(gz'); | ||
GADF_g=zeros(size(GADF_gx,1),size(GADF_gx,2),3); | ||
GADF_g(:,:,1)=mat2gray(GADF_gx); | ||
GADF_g(:,:,2)=mat2gray(GADF_gy); | ||
GADF_g(:,:,3)=mat2gray(GADF_gz); | ||
imwrite(GADF_g,[Inertial_GAF_path,path,'_GADF_g.jpg']); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
clc; | ||
clear; | ||
clear all; | ||
csv=importdata('carrying.csv'); | ||
csvdata=csv.data; | ||
ax = csvdata(:,2); %1-3 | ||
GADF_ax=GADF(ax'); | ||
imshow(mat2gray(GADF_ax)); | ||
|
||
% GASF_ax=GASF(ax'); | ||
% imshow(mat2gray(GASF_ax)); | ||
% ay = iner(:,2); | ||
% az = iner(:,3); | ||
|
||
% gx = iner(:,4); | ||
% gy = iner(:,5); | ||
% gz = iner(:,6); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
%Calculate the GAF inages in UTD-MHAD dataset | ||
clc; | ||
clear; | ||
clear all; | ||
GASF_or_GADF='GASF'; | ||
Inertial_path='D:\Multi-modal Action Recognition\MMAct\orientation_clip\'; | ||
%Inertial_GAF_path='D:\Postdoctoral Research\Multi-modal Action Recognition\Datasets\MMAct\trimmed-selected\acc_phone_clip_GAF\'; | ||
Inertial_data_dir = dir(Inertial_path); | ||
foldername = {Inertial_data_dir(:).name}; | ||
Inertial_data_subject_dir = setdiff(foldername,{'.','..'}); | ||
flag=1; | ||
for i=1:length(Inertial_data_subject_dir) | ||
scene_path=[Inertial_path,cell2mat(Inertial_data_subject_dir(i))]; | ||
scene_data_dir = dir(scene_path); | ||
foldername = {scene_data_dir.name}; | ||
Inertial_data_scene_dir = setdiff(foldername,{'.','..'}); | ||
for j=1:length(Inertial_data_scene_dir) | ||
session_path=[Inertial_path,cell2mat(Inertial_data_subject_dir(i)),'\',cell2mat(Inertial_data_scene_dir(j))]; | ||
session_data_dir = dir(session_path); | ||
foldername = {session_data_dir.name}; | ||
Inertial_data_session_dir = setdiff(foldername,{'.','..'}); | ||
for k=1:length(Inertial_data_session_dir) | ||
data_path=[Inertial_path,cell2mat(Inertial_data_subject_dir(i)),'\',cell2mat(Inertial_data_scene_dir(j)),'\',Inertial_data_session_dir(k)]; | ||
path_dir=dir([cell2mat(data_path) '/*.csv' ]); | ||
foldername = {path_dir.name}; | ||
data_dir = setdiff(foldername,{'.','..'}); | ||
for p=1:length(data_dir) | ||
fprintf('%d',flag); | ||
fprintf('\n'); | ||
flag=flag+1; | ||
Inertial=importdata([cell2mat(data_path),'\',cell2mat(data_dir(p))]); | ||
if ~isempty(Inertial) | ||
Inertial_data=Inertial.data; | ||
path=cell2mat(data_dir(p)); | ||
path=path(1:end-4); | ||
% if ~exist([cell2mat(data_path),'\',path,'_GAF'],'dir') | ||
% mkdir([cell2mat(data_path),'\',path,'_GAF']); | ||
% end | ||
if GASF_or_GADF=='GASF' | ||
ax = Inertial_data(:,1); | ||
GASF_ax=GASF(ax'); | ||
ay = Inertial_data(:,2); | ||
GASF_ay=GASF(ay'); | ||
az = Inertial_data(:,3); | ||
GASF_az=GASF(az'); | ||
GASF_a=zeros(size(GASF_ax,1),size(GASF_ax,2),3); | ||
GASF_a(:,:,1)=mat2gray(GASF_ax); | ||
GASF_a(:,:,2)=mat2gray(GASF_ay); | ||
GASF_a(:,:,3)=mat2gray(GASF_az); | ||
imwrite(GASF_a,[cell2mat(data_path),'\',data_path{2},'_',data_path{4},'_',data_path{6},'_', path,'_GASF_orientation.jpg']);%_acc_phone,_acc_watch,gyro,orientation | ||
|
||
% gx = Inertial_data.d_iner(:,4); | ||
% GASF_gx=GASF(gx'); | ||
% gy = Inertial_data.d_iner(:,5); | ||
% GASF_gy=GASF(gy'); | ||
% gz = Inertial_data.d_iner(:,6); | ||
% GASF_gz=GASF(gz'); | ||
% GASF_g=zeros(size(GASF_gx,1),size(GASF_gx,2),3); | ||
% GASF_g(:,:,1)=mat2gray(GASF_gx); | ||
% GASF_g(:,:,2)=mat2gray(GASF_gy); | ||
% GASF_g(:,:,3)=mat2gray(GASF_gz); | ||
% imwrite(GASF_g,[Inertial_GAF_path,path,'\GASF_g.jpg']); | ||
else if GASF_or_GADF=='GADF' | ||
ax = Inertial_data(:,1); | ||
GADF_ax=GADF(ax'); | ||
ay = Inertial_data(:,2); | ||
GADF_ay=GADF(ay'); | ||
az = Inertial_data(:,3); | ||
GADF_az=GADF(az'); | ||
GADF_a=zeros(size(GADF_ax,1),size(GADF_ax,2),3); | ||
GADF_a(:,:,1)=mat2gray(GADF_ax); | ||
GADF_a(:,:,2)=mat2gray(GADF_ay); | ||
GADF_a(:,:,3)=mat2gray(GADF_az); | ||
imwrite(GADF_a,[cell2mat(data_path),'\',data_path{2},'_',data_path{4},'_',data_path{6},'_',path,'_GADF_acc_phone.jpg']);%_acc_phone,_acc_watch,gyro,orientation | ||
|
||
% gx = Inertial_data.d_iner(:,4); | ||
% GADF_gx=GADF(gx'); | ||
% gy = Inertial_data.d_iner(:,5); | ||
% GADF_gy=GADF(gy'); | ||
% gz = Inertial_data.d_iner(:,6); | ||
% GADF_gz=GADF(gz'); | ||
% GADF_g=zeros(size(GADF_gx,1),size(GADF_gx,2),3); | ||
% GADF_g(:,:,1)=mat2gray(GADF_gx); | ||
% GADF_g(:,:,2)=mat2gray(GADF_gy); | ||
% GADF_g(:,:,3)=mat2gray(GADF_gz); | ||
% imwrite(GADF_g,[Inertial_GAF_path,path,'\GADF_g.jpg']); | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
%Calculate the GAF inages in UTD-MHAD dataset | ||
clc; | ||
clear; | ||
clear all; | ||
GASF_or_GADF='GADF'; | ||
Inertial_path='D:\Postdoctoral\Multi-modal-Action-Recognition\Datasets\UTD-MHAD\Inertial\'; | ||
Inertial_GAF_path='D:\Postdoctoral\Multi-modal-Action-Recognition\Datasets\UTD-MHAD\Inertial_GAF\'; | ||
Inertial_data_dir = dir(Inertial_path); | ||
foldername = {Inertial_data_dir(:).name}; | ||
Inertial_data_dir = setdiff(foldername,{'.','..'}); | ||
|
||
for i=1:length(Inertial_data_dir) | ||
|
||
path=cell2mat(Inertial_data_dir(i)); | ||
Inertial_data=load([Inertial_path,path]); | ||
path=path(1:end-4); | ||
if ~exist([Inertial_GAF_path,path],'dir') | ||
mkdir([Inertial_GAF_path,path]); | ||
end | ||
if GASF_or_GADF=='GASF' | ||
ax = Inertial_data.d_iner(:,1); | ||
GASF_ax=GASF(ax'); | ||
ay = Inertial_data.d_iner(:,2); | ||
GASF_ay=GASF(ay'); | ||
az = Inertial_data.d_iner(:,3); | ||
GASF_az=GASF(az'); | ||
GASF_a=zeros(size(GASF_ax,1),size(GASF_ax,2),3); | ||
GASF_a(:,:,1)=mat2gray(GASF_ax); | ||
GASF_a(:,:,2)=mat2gray(GASF_ay); | ||
GASF_a(:,:,3)=mat2gray(GASF_az); | ||
imwrite(GASF_a,[Inertial_GAF_path,path,'_GASF_a.jpg']); | ||
|
||
gx = Inertial_data.d_iner(:,4); | ||
GASF_gx=GASF(gx'); | ||
gy = Inertial_data.d_iner(:,5); | ||
GASF_gy=GASF(gy'); | ||
gz = Inertial_data.d_iner(:,6); | ||
GASF_gz=GASF(gz'); | ||
GASF_g=zeros(size(GASF_gx,1),size(GASF_gx,2),3); | ||
GASF_g(:,:,1)=mat2gray(GASF_gx); | ||
GASF_g(:,:,2)=mat2gray(GASF_gy); | ||
GASF_g(:,:,3)=mat2gray(GASF_gz); | ||
imwrite(GASF_g,[Inertial_GAF_path,path,'_GASF_g.jpg']); | ||
else if GASF_or_GADF=='GADF' | ||
ax = Inertial_data.d_iner(:,1); | ||
GADF_ax=GADF(ax'); | ||
ay = Inertial_data.d_iner(:,2); | ||
GADF_ay=GADF(ay'); | ||
az = Inertial_data.d_iner(:,3); | ||
GADF_az=GADF(az'); | ||
GADF_a=zeros(size(GADF_ax,1),size(GADF_ax,2),3); | ||
GADF_a(:,:,1)=mat2gray(GADF_ax); | ||
GADF_a(:,:,2)=mat2gray(GADF_ay); | ||
GADF_a(:,:,3)=mat2gray(GADF_az); | ||
imwrite(GADF_a,[Inertial_GAF_path,path,'_GADF_a.jpg']); | ||
|
||
gx = Inertial_data.d_iner(:,4); | ||
GADF_gx=GADF(gx'); | ||
gy = Inertial_data.d_iner(:,5); | ||
GADF_gy=GADF(gy'); | ||
gz = Inertial_data.d_iner(:,6); | ||
GADF_gz=GADF(gz'); | ||
GADF_g=zeros(size(GADF_gx,1),size(GADF_gx,2),3); | ||
GADF_g(:,:,1)=mat2gray(GADF_gx); | ||
GADF_g(:,:,2)=mat2gray(GADF_gy); | ||
GADF_g(:,:,3)=mat2gray(GADF_gz); | ||
imwrite(GADF_g,[Inertial_GAF_path,path,'_GADF_g.jpg']); | ||
end | ||
end | ||
|
||
end |