# Depth-Oriented Gray Image for Unseen Pig Detection in Real Time
## 3 Materials and Methods
### DOG Generation Module  
The process for generating DOG images, aimed at generalizing test images and improving the accuracy of object detection models, is illustrated in Figure 4. The proposed DOG Generation Module leverages the depth background images produced during the preprocessing stage to achieve real-time depth-like image generation. Initially, the pixel values of both the grayscale image and the depth background image are summed. This step mitigates the brightness inconsistencies caused by lighting variations and environmental factors, enabling the enhanced representation of object contours and details. Subsequently, Contrast-Limited Adaptive Histogram Equalization (CLAHE) was applied with parameters set to clipLimit = 4 and tileGridSize = (4, 4) to enhance contrast. clipLimit = 4 was chosen to effectively prevent excessive noise amplification, preserving the integrity of the image during processing. tileGridSize = (4, 4) was utilized to emphasize differences in smaller regions, which allowed for the precise delineation of boundaries between the floor and pigpen walls, as well as the edges of objects. This contrast enhancement improved the distinction between the foreground and background, allowing the object detection model to effectively identify the RoI. Following the application of CLAHE, the histograms of the grayscale image and the depth background image were equalized, and the two images were combined using equal weights. The reason for applying equal weights was to maintain a balanced contribution between the grayscale image, which contains objects, and the depth background image, which does not contain objects. Figure 3: Structure of RoI Setting Module. Grayscale images often struggle to differentiate between the foreground and background under varying lighting conditions or due to the presence of diverse floor materials. To address this challenge, the depth background information is merged with the grayscale image using equal weighting to create a composite image. This composite image retains the structural details and contours of the objects in the grayscale image while effectively incorporating depth background information. Finally, element-wise multiplication is performed between this composite image and the inverted saturation component of the HSV color space. This process emphasizes low-saturation foreground regions, such as pigs, while suppressing high-saturation regions containing rich color information, resulting in the final DOG image. Figure 5 illustrates the HSV images derived from the input video. The HSV-Hue component, which separates colors such as red, green, and blue into angles in the color space, was not utilized because it is heavily influenced by color and fails to represent pixel values of objects within the image consistently. In contrast, HSV-Saturation defines lower values as achromatic regions, and when inverted, achromatic objects are represented with higher pixel values. This characteristic provides compelling features when performing element-wise multiplication. HSV-Value, generated based on the maximum value in the red, green, and blue color space, vividly highlights the texture of objects. Figure 4: Overview of DOG Generation Module. Figure 5: Hue, saturation, and value of the input image with (**a**) HSV-Hue, (**b**) HSV-Saturation, and (**c**) HSV-Value. Algorithm 1 describes the process for generating RoI and DOG images from a sequence of video frames. It involves preprocessing steps to define RoIs, creating depth background images, and generating DOG images to enhance object detection accuracy in unseen environments. By leveraging deep learning-based foundation models (SAM, LaMa, Depth Anything) and simple image processing techniques, the algorithm ensures efficient real-time performance. ```
Input:  Frame: video frame sequence \(\text{F}=\{f_{1},\ f_{2}\dots f_{n}\}\). Output:  Region of Interest (RoI) image;  Depth background (DB) image;  Depth-oriented gray (DOG) image. ```  
For each frame, carry out \(f\in F\).