## 2 Materials and Methods  
### Development of an Automated Behavioral Pattern Analysis Program  
The automated behavioral pattern analysis program, using a depth-image camera, was developed as follows. The automated analysis program for classifying behavioral patterns was mainly based on background elimination and object tracking algorithms, which include the Gaussian mixture model, morphological filtering, centroid, noise reduction, and classification algorithms. To eliminate unnecessary parts around the cage from the depth image, a 3-D region of interest was defined inside the volumetric area of the cage (width \(\times\) depth \(\times\) height = 50 cm \(\times\) 100 cm \(\times\) 84 cm). The automated program consisted of the following procedures (Figure 1). 1. Importing real time image frames: a camera (Microsoft Kinect V2 Window) we used for capturing motions of object has 2 types of camera module, one is a RGB images sensor for gathering ColorFrame and the other is depth sensor for acquiring DepthFrame images. Both were utilized as raw images and imported to the analysis computer in real time;
2. Image mapping: the ColorFrame, obtained from RGB image sensor module, and Depth Frame from a depth sensor have different image resolutions. The MS Kinect V2 provides 1920 \(\times\) 1080 resolution by RGB images and 512 \(\times\) 424 resolution by depth images. For mapping two different resolution images, we merged ColorFrame with DepthFrame as Figure 1a. Both merged images and raw images from a depth camera were utilized in following steps;3. Region of interest selection: in order to select the region of interest (ROI) inside a cage in the z direction, image data between the depth camera and the top of cage denoted as \"Front Barrier\" and image data below the bottom of the cage denoted as \"Rear Barrier\" were eliminated (Figure 2); 4. In order to select the ROI inside a cage in the z-y plane, image data outside a cage were eliminated. The removal area is shown as a grey rectangular box in which each side is denoted as \"Top,\" \"Bottom,\" \"Left,\" and \"Right\" (Figure 2). Figure 1b depicted processed images after applying step 3 and step 4 to raw images;
5. Noise reduction: after recording 30 frames of image data, the pixels which underwent a small change equal to the specified value were removed (Figure 3a). Then, the \"blur\" function was used to eliminate minor noise in the image data (Figure 3b). The minor noise is defined as unnecessary pixels for object identification and disregarded for enhancing following image processing steps;  
Figure 1: (**a**) Merged image from ColorFrame + DepthFrame and (**b**) Image after applying step 3 and 4. Figure 2: A three dimensional R.O.I selection inside a cage. 6. Background elimination: the \"BackgroundSubtractorMOG2\" in OpenCV was used for separating the targeted object from raw images based on Gaussian mixture method to eliminate background (Figure 3c). We can acquire a clear object image through this processing step;
7. 2 nd noise reduction: any group of pixels smaller than 5-pixel size of processing image were considered as a noise and replaced by black (0 value) pixels. Then, we applied a \"Morphology method\" three times from \"dilate\" to \"erode\" for obtaining clear object image. The \"dilate\" processing converted the positive pixels into the most bright value of the image while the \"erode\" processing changed negative pixels to the darkest value (Figure 3d);
8. Creating contour and a center spot: the \"findCountours\" in OpenCV was used to create the contour of an object. After adopting contouring algorithm to the images, we were able to get a refined shape of the object. Then, we applied \"Centroid Based\" algorithm in Open CV for finding a center spot of the image;
9. Find the representing point of an object: rhe centroid of an object was tracked in real time and the pixel of the smallest depth value inside the centroid area as the measuring point of an object was found.