-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_gaf.py
More file actions
73 lines (58 loc) · 2.68 KB
/
Copy pathplot_gaf.py
File metadata and controls
73 lines (58 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
""""
# Gramian Angular Field
A Gramian Angular Field is an image obtained from a time series, representing
some temporal correlation between each time point. Two methods are
available: Gramian Angular Summation Field and Gramian Angular Difference
Field. This example illustrates the transformation on the first sample of
the *GunPoint* dataset. Both images are plotted side by side to illustrate
the differences.
It is implemented as :class:`pyts.image.GramianAngularField`.
"""
# Author: Johann Faouzi <johann.faouzi@gmail.com>
# License: BSD-3-Clause
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
from pyts.image import GramianAngularField
from numpy import genfromtxt
from pathlib import Path, PureWindowsPath
import os
import numpy as np
import glob
# Parameters
file_path = 'D:\dev\Mestrado\Onlydata-features-3.csv'
savepathgasf = 'D:\\TCC\\ImagemTeste\\Normalizadas\\ROIs_normalizadas\\moderado\\Método proposto\\moderado\\GASF\\'
savepathgadf = 'D:\\TCC\\ImagemTeste\\Normalizadas\\ROIs_normalizadas\\moderado\\Método proposto\\moderado\\GADF\\'
#Make save dir if not exists
if not os.path.exists(savepathgasf):
os.makedirs(savepathgasf)
if not os.path.exists(savepathgadf):
os.makedirs(savepathgadf)
# Get data from csv
X = genfromtxt(file_path, delimiter=',')
n_img = len(X)
#Define data range
a = X[0:n_img, 0:300]
for i in range (n_img):
b = a[i, 0:300]
X = b
X = X.reshape(3, 100)
# Transform the time series into Gramian Angular Fields
gasf = GramianAngularField(method='summation')
X_gasf = gasf.fit_transform(X)
gadf = GramianAngularField(method='difference')
X_gadf = gadf.fit_transform(X)
plt.imsave(savepathgasf+'GRAYGASFMink'+str(i+1)+'.png', X_gasf[0], cmap='gray', origin='lower')
plt.imsave(savepathgasf+'GRAYGASFEucl'+str(i+1)+'.png', X_gasf[1], cmap='gray', origin='lower')
plt.imsave(savepathgasf+'GRAYGASFManh'+str(i+1)+'.png', X_gasf[2], cmap='gray', origin='lower')
plt.imsave(savepathgadf+'GRAYGADFMink'+str(i+1)+'.png', X_gadf[0], cmap='gray', origin='lower')
plt.imsave(savepathgadf+'GRAYGADFEucl'+str(i+1)+'.png', X_gadf[1], cmap='gray', origin='lower')
plt.imsave(savepathgadf+'GRAYGADFManh'+str(i+1)+'.png', X_gadf[2], cmap='gray', origin='lower')
imagem = np.reshape(X_gasf, (100, 100,3))
imagem = (255*(imagem - np.min(imagem))/np.ptp(imagem)).astype(int)
imagem = np.uint8(imagem)
plt.imsave(savepathgasf+'GASF'+str(i+1)+'.png', imagem, origin='lower')
imagem = np.reshape(X_gadf, (100, 100,3))
imagem = (255*(imagem - np.min(imagem))/np.ptp(imagem)).astype(int)
imagem = np.uint8(imagem)
plt.imsave(savepathgadf+'GADF'+str(i+1)+'.png', imagem, origin='lower')
print('imagens salvas no diretorios')