# Pedestrian Localization in a Video Sequence Using Motion Detection and Active Shape Models
## 3 Experimental Set-Up
### Motion Detection by Background Subtraction (MDBS)  
In this stage, the challenge is to detect regions of movement. The motion detection with background subtraction technique is proposed to separate the object of interest (foreground) from the background. Algorithm 1 shows the main steps for the detection of motion regions. The detailed sequence to perform the detection of the movement is as follows:  
Figure 1: Scenes selected from the CDnet2014 database: (**a**) office, (**b**) PETS2006, and (**c**) sofa. Figure 2: Scenes selected from the CASIA Gait dataset: (**a**) pedestrian walking at 0 degrees, (**b**) at 36 degrees, (**c**) at 54 degrees, and (**d**) at 90 degrees. 1. Convert the first frame \(I\) of the video sequence to grayscale and set it as the background \(F\) background frame (\(F\)). 2. Read the next frame in the video sequence \((I)\) and convert it to grayscale. 3. Subtract the background \(F\) from the image with Equation (1) for every pixel \((x,y)\) in the image. \[B(x,y)=I(x,y)-F(x,y)\] (1)
4. Binarize \(B\), considering a threshold \(Th=61\). Values greater than \(Th\) are normalized to 1, and values less than \(Th\) are normalized to 0; consequently, the possible pedestrian contour is segmented. \(Th\) is computed by [PERSON]'s method [32]. This considered one of the best and most stable methods for choosing threshold values automatically [33]. The simplicity of procedure characterizes [PERSON]'s method, and it is a non-parametric, valuable technique because of its unsupervised nature for threshold selection. It minimizes the intraclass variance of black and white pixels to obtain a optimal threshold (\(Th\)), following a sequential search and using the simple cumulative quantities as follows: Consider that \(G=[0,L-1]\) is the range of the grayscale of an image \(f(x,y)\) and \(P_{i}\) is the probability of \(i\) grayscale level. The threshold value \(i\) splits the image into two classes \(C_{0}=[0,t]\) and \(C_{1}[t+1,L-1]\), with probabilities of \(\alpha_{0}=\sum_{i=0}^{t}P_{i}\) and \(\alpha_{1}=1-\alpha_{0}\), respectively. The means \((\mu)\) of the gray values to \(C_{0}\) and \(C_{1}\) are \(\mu_{0}=\sum_{i=0}^{t}iP_{i}/\alpha_{0}=\mu_{t}/\alpha_{0}\) and \(\mu_{1}=\sum_{i=t+1}^{L-1}iP_{1}/\alpha_{1}=(\mu-\mu_{t})/(1-\alpha_{1})\), respectively, where \(\mu=\sum_{i=0}^{L-1}iP_{i}\) and \(\mu_{t}=\sum_{i=0}^{t}iP_{i}\). Thus, the criterion function is defined in Equation (2) as the variance between two classes (\(C_{0}\) and \(C_{1}\)), where the optimal threshold \(Th\) is the \(t\) value that maximizes \(\eta\). \[\eta^{2}(t)=\alpha_{0}(\mu_{0}-\mu)^{2}+\alpha_{1}(\mu_{1}-\mu)^{2}=\alpha_{0 }\alpha_{1}(\mu_{0}-\mu_{1})^{2}.\] (2) In this case, the calculation of \(Th\) was carried out under controlled conditions in environments with artificial light. 5. Erode \(B\), using a circular structured element \(E\) of radius \(R=5\), which helps to round the contour. \(R=5\) was obtained through a trial-and-error strategy (a greedy solution). This result is a tread-off between the frame resolution and the person's scale into the frame. 6. Eliminate residuals in \(B\) applying the 4-neighbor technique, using the set of isolated pixels of the person's silhouette as the residual. 7. Fill gaps in \(B\), which contain 0 values inside the outline of the person's silhouette. 8. Calculate the equation of the regression line, which is used to delimit the region of interest where the moving object was detected (Equation (3)). \[y^{\prime}=a_{0}+a_{1}x,\] (3) where \(y^{\prime}\) is the estimated ordinate of the \(n\) points \((x,y)\), which correspond to the pixels in \(B\) whose values are 1; \(a_{0}\) and \(a_{1}\) are constants that get the values of the normal equations of the least-squares line, which in essence form a system of two equations whose solutions are defined by Equations (4) and (5). \[\sum_{i=1}^{n}y_{i}=na_{0}+\sum_{i=1}^{n}a_{1}x_{i}, \tag{4}\]  
\[\sum_{i=1}^{n}x_{i}y_{i}=a_{0}\sum_{i=1}^{n}x_{i}+\sum_{i=1}^{n}a_{1}x_{i}^{2}, \tag{5}\]
9.