# Camera-Based Continuous Heart and Respiration Rate Monitoring in the ICU
## 2 Materials and Methods
### Respiration Rate Extraction
#### 2.5.5 Detection of Breathing Motion Errors  
The M1D-OF method [10] cannot yet differentiate between breathing and other motion in the chest ROI, leading to inaccurate respiration measurements in segments containing non-breathing motion. Here, we developed a metric to detect when non-breathing motion occurred such that inaccurate measurements could be discarded. The image brightness function \(I(x,y,t)\) describes the brightness of the pixels in the chest ROI over time. The gradient constraint equation [26] describes how optical flow, i.e., motion, relates to the image brightness function. The gradient constraint equation at time \(t\) is written as follows:  
\[-I_{t}(x,y)=v_{x}(x,y)I_{x}(x,y)+v_{y}(x,y)I_{y}(x,y), \tag{1}\]  
where \(I_{t}\), \(I_{x}\), and \(I_{y}\) are gradients of the brightness function toward their respective variables. The calculation of these gradients is detailed by [PERSON] et al. [10]. Finally, \(v_{x}\) and \(v_{y}\) represent the horizontal and vertical motion. To solve Equation (1) for \(v_{x}\) and \(v_{y}\), the M1D-OF method of [PERSON] et al. [10] constrains the solution through the assumption that breathing motion is equal across the chest ROI and that the motion is only in the vertical direction. In terms of Equation (1), this means that \(v_{x}=0\) for all \(x,y\in ROI\) and that \(v_{y}\) is constant over all \(x,y\). Given these assumptions, the least squares (LSs) solution of \(v_{y}\) is defined as follows:  
\[\partial_{y}=-(\mathbf{D_{y}}^{\mathrm{T}}\mathbf{D_{y}})^{-1}\mathbf{D_{y}}^ {\mathrm{T}}\mathbf{D_{t}}. \tag{2}\]  
Here, \(\mathbf{D_{y}}\) and \(\mathbf{D_{t}}\) are column vectors containing, respectively, the spatial and temporal gradients of each pixel in the chest ROI. This LSs solution minimizes residual error \(r\):  
\[r=||\mathbf{D_{y}}\cdot\partial_{y}+\mathbf{D_{t}}||_{2}^{2}. \tag{3}\]  
The constrained model of optical flow in the chest ROI only fits well to motion that does indeed adhere to the restrictions. We can argue that the constrained solution \(v_{y}\) in Equation (2) will generally not be a good solution to Equation (1) if \(v_{x}\
eq 0\) and/or \(v_{y}\) is not the same across all \(x,y\in ROI\). In terms of the residual error, we can write the following:  
\[\mathbf{D_{t}}=-\mathbf{V_{x}}\cdot\mathbf{D_{x}}-\mathbf{V_{y}}\cdot \mathbf{D_{y}}, \tag{4}\]  
where \(\mathbf{V_{x}}\) and \(\mathbf{V_{y}}\) are the vectors of the true velocities \(v_{y}(x,y)\) and \(v_{x}(x,y)\) of all pixels in the chest ROI. If we substitute Equation (4) into Equation (3), we obtain  
\[r=||\mathbf{D_{y}}\cdot(\partial_{y}-\mathbf{V_{y}})-\mathbf{V_{x}}\cdot \mathbf{D_{x}}||_{2}^{2}. \tag{5}\]  
As such, the residual error contains the unmodeled motion in the horizontal direction and the difference between the true motion in the vertical direction relative to the solution \(\partial_{y}\). Thus, any pixel in the ROI that contains motion that does not adhere to the constrained model will contribute to an increase in residual error. Indicating an increase in residual error could be a sign of non-breathing motion. An additional source of residual error is the measurement error in spatial \(I_{y}\) and temporal \(I_{t}\) gradients, as explained by [PERSON] et al. [26], which is caused by the sensor and quantization noise. Furthermore, systematic error arises from non-linearity in image brightness \(I(x,y)\), especially at sudden changes like blanket edges. Although small motions, such as breathing, are less affected, large non-breathing motions could be amplified by non-linearity in the brightness function [26]. To summarize, non-breathing motion errors consist of unmodeled dynamics, and thus, the error changes with the direction and magnitude of the non-breathing motionand could be further amplified by non-linearity in the brightness function. In contrast, measurement error is unrelated to motion and will change slowly over time with changes in lighting conditions.