File size: 908 Bytes
39b4c8c |
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 |
from sklearn import decomposition
from numpy import vstack
from .base import VHRMethod
class PCA(VHRMethod):
methodName = 'PCA'
def __init__(self, **kwargs):
super(PCA, self).__init__(**kwargs)
def apply(self, X):
# TODO: preproc
#X = self.__preprocess(X.T)
bvp = decomposition.PCA(n_components=3).fit_transform(X.T).T
return bvp
def __preprocess(self, X):
R = X[:,0].copy()
G = X[:,1].copy()
B = X[:,2].copy()
# -- BP pre-filtering of RGB channels
minHz = BVPsignal.minHz
maxHz = BVPsignal.maxHz
fs = self.video.frameRate
# -- filter
filteredR = BPfilter(R, minHz, maxHz, fs)
filteredG = BPfilter(G, minHz, maxHz, fs)
filteredB = BPfilter(B, minHz, maxHz, fs)
X = vstack([filteredR, filteredG, filteredB])
return X |