pyVHR.BVP package

Submodules

pyVHR.BVP.BVP module

pyVHR.BVP.BVP.RGB_sig_to_BVP(windowed_sig, fps, device_type=None, method=None, params={})

Transform an input RGB windowed signal in a BVP windowed signal using a rPPG method (see pyVHR.BVP.methods). You can pass also non-RGB signal but the method used must handle its shape.

Parameters
  • windowed_sig (list) – RGB windowed signal as a list of length num_windows of np.ndarray with shape [num_estimators, rgb_channels, num_frames].

  • fps (float) – frames per seconds. You can pass also a generic signal but the method used must handle its shape and type.

  • device_type (str) – the chosen rPPG method run on GPU (‘cuda’), or CPU (‘cpu’, ‘torch’).

  • method – a method that comply with the fucntion signature documented in pyVHR.BVP.methods. This method must use Numpy if the ‘device_type’ is ‘cpu’, Torch if the ‘device_type’ is ‘torch’, and Cupy if the ‘device_type’ is ‘cuda’.

  • params (dict) – dictionary of usefull parameters that will be passed to the method. If the method needs fps you can set {‘fps’:’adaptive’} in the dictionary to use the ‘fps’ input variable.

Returns

a list of lenght num_windows of BVP signals as np.ndarray with shape [num_estimators, num_frames]; if no BVP can be found in a window, then the np.ndarray has num_estimators == 0.

pyVHR.BVP.BVP.concatenate_BVPs(list_of_BVPs)

Join a list of windowed BVPs. There must be the same number of windows, and each one must have the same number of frames.

Parameters

list_of_BVPs (list) – a list of windowed BVPs each one defined as a list of lenght num_windows of BVP signals as np.ndarray with shape [num_estimators, num_frames]. Remember that concatenation is possible only if ‘num_frames’ is the same for each BVP of the nth window.

Returns

a list of lenght num_windows of BVP signals as np.ndarray with shape [total_num_estimators, num_frames]; if no BVP can be found in a window, then the np.ndarray has total_num_estimators == 0. For example: given the BVP windows of shape [10, 200] and [20,200], the concatenated window will have shape [30,200]; If an exception is thrown for any reason, the function returns 0.

pyVHR.BVP.BVP.signals_to_bvps_cpu(sig, cpu_method, params={})

Transform an input RGB signal in a BVP signal using a rPPG method (see pyVHR.BVP.methods). This method must use and execute on CPU. You can pass also non-RGB signal but the method used must handle its shape.

Parameters
  • sig (float32 ndarray) – RGB Signal as float32 ndarray with shape [num_estimators, rgb_channels, num_frames]. You can pass also a generic signal but the method used must handle its shape and type.

  • cpu_method – a method that comply with the fucntion signature documented in pyVHR.BVP.methods. This method must use Numpy.

  • params (dict) – dictionary of usefull parameters that will be passed to the method.

Returns

BVP signal as float32 ndarray with shape [num_estimators, num_frames].

Return type

float32 ndarray

pyVHR.BVP.BVP.signals_to_bvps_cuda(sig, cupy_method, params={})

Transform an input RGB signal in a BVP signal using a rPPG method (see pyVHR.BVP.methods). This method must use cupy and executes on GPU. You can pass also non-RGB signal but the method used must handle its shape.

Parameters
  • sig (float32 ndarray) – RGB Signal as float32 ndarray with shape [num_estimators, rgb_channels, num_frames]. You can pass also a generic signal but the method used must handle its shape and type.

  • cupy_method – a method that comply with the fucntion signature documented in pyVHR.BVP.methods. This method must use Cupy.

  • params (dict) – dictionary of usefull parameters that will be passed to the method.

Returns

BVP signal as float32 ndarray with shape [num_estimators, num_frames].

Return type

float32 ndarray

pyVHR.BVP.BVP.signals_to_bvps_torch(sig, torch_method, params={})

Transform an input RGB signal in a BVP signal using a rPPG method (see pyVHR.BVP.methods). This method must use Torch and execute on GPU/CPU. You can pass also non-RGB signal but the method used must handle its shape.

Parameters
  • sig (float32 ndarray) – RGB Signal as float32 ndarray with shape [num_estimators, rgb_channels, num_frames]. You can pass also a generic signal but the method used must handle its shape and type.

  • torch_method – a method that comply with the fucntion signature documented in pyVHR.BVP.methods. This method must use Torch.

  • params (dict) – dictionary of usefull parameters that will be passed to the method.

Returns

BVP signal as float32 ndarray with shape [num_estimators, num_frames].

Return type

float32 ndarray

pyVHR.BVP.methods module

This module contains a collection of known rPPG methods.

rPPG METHOD SIGNATURE:
  • ‘signal’: RGB signal as float32 ndarray with shape [num_estimators, rgb_channels, num_frames], or a custom signal.

  • ‘**kargs’ [OPTIONAL]: usefull parameters passed to the filter method.

An rPPG method must return a BVP signal as float32 ndarray with shape [num_estimators, num_frames].

pyVHR.BVP.methods.cpu_CHROM(signal)

CHROM method on CPU using Numpy.

De Haan, G., & Jeanne, V. (2013). Robust pulse rate from chrominance-based rPPG. IEEE Transactions on Biomedical Engineering, 60(10), 2878-2886.

pyVHR.BVP.methods.cpu_GREEN(signal)

GREEN method on CPU using Numpy

Verkruysse, W., Svaasand, L. O., & Nelson, J. S. (2008). Remote plethysmographic imaging using ambient light. Optics express, 16(26), 21434-21445.

pyVHR.BVP.methods.cpu_ICA(signal, **kargs)

ICA method on CPU using Numpy.

The dictionary parameters are {‘component’:str}. Where ‘component’ can be ‘second_comp’ or ‘all_comp’.

Poh, M. Z., McDuff, D. J., & Picard, R. W. (2010). Non-contact, automated cardiac pulse measurements using video imaging and blind source separation. Optics express, 18(10), 10762-10774.

pyVHR.BVP.methods.cpu_LGI(signal)

LGI method on CPU using Numpy.

Pilz, C. S., Zaunseder, S., Krajewski, J., & Blazek, V. (2018). Local group invariance for heart rate estimation from face videos in the wild. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition Workshops (pp. 1254-1262).

pyVHR.BVP.methods.cpu_PBV(signal)

PBV method on CPU using Numpy.

De Haan, G., & Van Leest, A. (2014). Improved motion robustness of remote-PPG by using the blood volume pulse signature. Physiological measurement, 35(9), 1913.

pyVHR.BVP.methods.cpu_PCA(signal, **kargs)

PCA method on CPU using Numpy.

The dictionary parameters are {‘component’:str}. Where ‘component’ can be ‘second_comp’ or ‘all_comp’.

Lewandowska, M., Rumiński, J., Kocejko, T., & Nowak, J. (2011, September). Measuring pulse rate with a webcam—a non-contact method for evaluating cardiac activity. In 2011 federated conference on computer science and information systems (FedCSIS) (pp. 405-410). IEEE.

pyVHR.BVP.methods.cpu_POS(signal, **kargs)

POS method on CPU using Numpy.

The dictionary parameters are: {‘fps’:float}.

Wang, W., den Brinker, A. C., Stuijk, S., & de Haan, G. (2016). Algorithmic principles of remote PPG. IEEE Transactions on Biomedical Engineering, 64(7), 1479-1491.

pyVHR.BVP.methods.cpu_SSR(raw_signal, **kargs)

SSR method on CPU using Numpy.

‘raw_signal’ is a float32 ndarray with shape [num_frames, rows, columns, rgb_channels]; it can be obtained by using the :py:class:‵pyVHR.extraction.sig_processing.SignalProcessing‵ class (‘extract_raw_holistic’ method).

The dictionary parameters are: {‘fps’:float}.

Wang, W., Stuijk, S., & De Haan, G. (2015). A novel algorithm for remote photoplethysmography: Spatial subspace rotation. IEEE transactions on biomedical engineering, 63(9), 1974-1984.

pyVHR.BVP.methods.cupy_CHROM(signal)

CHROM method on GPU using Cupy.

De Haan, G., & Jeanne, V. (2013). Robust pulse rate from chrominance-based rPPG. IEEE Transactions on Biomedical Engineering, 60(10), 2878-2886.

pyVHR.BVP.methods.cupy_POS(signal, **kargs)

POS method on GPU using Cupy.

The dictionary parameters are: {‘fps’:float}.

Wang, W., den Brinker, A. C., Stuijk, S., & de Haan, G. (2016). Algorithmic principles of remote PPG. IEEE Transactions on Biomedical Engineering, 64(7), 1479-1491.

pyVHR.BVP.methods.torch_CHROM(signal)

CHROM method on CPU using Torch.

De Haan, G., & Jeanne, V. (2013). Robust pulse rate from chrominance-based rPPG. IEEE Transactions on Biomedical Engineering, 60(10), 2878-2886.

pyVHR.BVP.filters module

This module contains a collection of filter methods.

FILTER METHOD SIGNATURE:
  • ‘signal’: RGB signal as float32 ndarray with shape [num_estimators, rgb_channels, num_frames], or BVP signal as float32 ndarray with shape [num_estimators, num_frames].

  • ‘**kargs’ [OPTIONAL]: usefull parameters passed to the filter method.

A filter method must return a filtered signal with the same shape as the input signal.

pyVHR.BVP.filters.BPfilter(sig, **kargs)

Band Pass filter (using BPM band) for RGB signal and BVP signal.

The dictionary parameters are: {‘minHz’:float, ‘maxHz’:float, ‘fps’:float, ‘order’:int}

pyVHR.BVP.filters.apply_filter(windowed_sig, filter_func, fps=None, params={})

Apply a filter method to a windowed RGB signal or BVP signal.

Parameters
  • windowed_sig – list of length num_window of RGB signal as float32 ndarray with shape [num_estimators, rgb_channels, num_frames], or BVP signal as float32 ndarray with shape [num_estimators, num_frames].

  • filter_func – filter method that accept a ‘windowed_sig’ (pyVHR implements some filters in pyVHR.BVP.filters).

  • params (dict) – usefull parameters passed to the filter method.

Returns

A filtered signal with the same shape as the input signal.

pyVHR.BVP.filters.detrend(X, **kargs)

Detrending filter for RGB signal and BVP signal.

This code is based on the following article “An advanced detrending method with application to HRV analysis”. Tarvainen et al., IEEE Trans on Biomedical Engineering, 2002.

Code like: https://www.idiap.ch/software/bob/docs/bob/bob.rppg.base/v1.0.3/_modules/bob/rppg/cvpr14/filter_utils.html

The dictionary parameters are: {‘detLambda’:int,}. Where ‘detLambda’ is the smoothing parameter.

pyVHR.BVP.filters.kernel_rgb_filter_th(sig, RGB_LOW_TH, RGB_HIGH_TH)

This method performs the Color Threshold filter for RGB signal only. Please refer to the method pyVHR.BVP.filters.rgb_filter_th.

pyVHR.BVP.filters.rgb_filter_th(sig, **kargs)

Color Threshold filter for RGB signal only.

The i_th estimators is filterd if its signal is outside the LOW/HIGH thresholds color interval in at least one frame.

The dictionary parameters are: {‘RGB_LOW_TH’:int, ‘RGB_HIGH_TH’:int}. Where ‘RGB_LOW_TH’ and ‘RGB_HIGH_TH’ are RGB value ([0,255]) which describe the filter thresholds.

pyVHR.BVP.filters.sg_detrend(X, **kargs)

Remove the low-frequency components with the low-pass filter developed by Savitzky-Golay. It can be used for RGB signals and BVP signals.

The dictionary parameters are: {‘window_length’:int, ‘polyorder’:int}. Where ‘window_length’ is the length of the filter window (i.e. the number of coefficients). window_length must be a positive odd integer. ‘polyorder’ is the order of the polynomial used to fit the samples. polyorder must be less than window_length.

pyVHR.BVP.filters.zeromean(X)

Zero Mean filter for RGB signal and BVP signal.

pyVHR.BVP.filters.zscore(sig)

Z-score filter for RGB signal and BVP signal.

pyVHR.BVP.utils module

pyVHR.BVP.utils.jadeR(X, m=None, verbose=True)

Blind separation of real signals with JADE. jadeR implements JADE, an Independent Component Analysis (ICA) algorithm developed by Jean-Francois Cardoso. See http://www.tsi.enst.fr/~cardoso/guidesepsou.html , and papers cited at the end of the source file.

Translated into NumPy from the original Matlab Version 1.8 (May 2005) by Gabriel Beckers, http://gbeckers.nl .

Parameters
  • matrix (X -- an nxT data) – matrix.

  • are (m -- output matrix B has size mxn so that only m sources) – extracted. This is done by restricting the operation of jadeR to the m first principal components. Defaults to None, in which case m=n.

  • True. (verbose -- print info on progress. Default is) –

Returns

An m*n matrix B (NumPy matrix type), such that Y=B*X are separated sources extracted from the n*T data matrix X. If m is omitted, B is a square n*n matrix (as many sources as sensors). The rows of B are ordered such that the columns of pinv(B) are in order of decreasing norm; this has the effect that the most energetically significant components appear first in the rows of Y=B*X.

Quick notes (more at the end of this file): o This code is for REAL-valued signals. A MATLAB implementation of JADE for both real and complex signals is also available from http://sig.enst.fr/~cardoso/stuff.html o This algorithm differs from the first released implementations of JADE in that it has been optimized to deal more efficiently 1) with real signals (as opposed to complex) 2) with the case when the ICA model does not necessarily hold. o There is a practical limit to the number of independent components that can be extracted with this implementation. Note that the first step of JADE amounts to a PCA with dimensionality reduction from n to m (which defaults to n). In practice m cannot be very large (more than 40, 50, 60… depending on available memory) o See more notes, references and revision history at the end of this file and more stuff on the WEB http://sig.enst.fr/~cardoso/stuff.html o For more info on NumPy translation, see the end of this file. o This code is supposed to do a good job! Please report any problem relating to the NumPY code gabriel@gbeckers.nl

Copyright original Matlab code : Jean-Francois Cardoso <cardoso@sig.enst.fr> Copyright Numpy translation : Gabriel Beckers <gabriel@gbeckers.nl>

Module contents