-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessing.py
More file actions
62 lines (47 loc) · 1.88 KB
/
Copy pathpreprocessing.py
File metadata and controls
62 lines (47 loc) · 1.88 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
# -*- coding: utf-8 -*-
"""preprocessing.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/15o7KRaSeP5vRAIBbWxUVi8xWbgTs6eXf
"""
import numpy as np
import matplotlib.pyplot as plt
from skimage import data
import scipy.io as sio
from Path import AF_FILE_PATH, NORMAL_FILE_PATH
normal = sio.loadmat("./checkpoint_data/after_matlab_scripts/NormalRPeaks.mat")
af = sio.loadmat("./checkpoint_data/after_matlab_scripts/AfRPeaks.mat")
normalImages = np.empty([normal["NormalRPeaks"].shape[1], 360, 360])
afImages = np.empty([af["AfRPeaks"].shape[1], 360, 360])
for i in range(0, normal["NormalRPeaks"].shape[1]):
print("i")
print(i)
x = np.diff(np.array(normal["NormalRPeaks"][0][i][0], dtype=np.int16), 2)
fig = plt.figure(figsize=(3.6, 3.6))
plt.plot(x[0:-2], x[1:-1])
plt.xlim([-500, 500])
plt.ylim([-500, 500])
plt.axis("off")
fig.canvas.draw() # draw the canvas, cache the renderer
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
image = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
image = image[:, :, 0] / 256
normalImages[i, :, :] = image
np.save(NORMAL_FILE_PATH, normalImages)
for i in range(0, af["AfRPeaks"].shape[1]):
print("i")
print(i)
i_new = i
x = np.diff(np.array(af["AfRPeaks"][0][i_new][0], dtype=np.int16), 2)
fig = plt.figure(figsize=(5, 5))
plt.plot(x[0:-2], x[1:-1])
plt.xlim([-500, 500])
plt.ylim([-500, 500])
plt.axis("off")
fig.canvas.draw() # draw the canvas, cache the renderer
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
image = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
image = image[:, :, 0] / 256
afImages[i, :, :] = image
print(image.shape)
np.save(AF_FILE_PATH, afImages)