# Depth-Oriented Gray Image for Unseen Pig Detection in Real Time
## 3 Materials and Methods  
This study utilizes recently introduced deep learning-based foundation models, including the SAM, LaMa, and Depth Anything. The SAM is a deep learning-based object segmentation model trained on large-scale datasets, capable of generating foreground object masks based on user inputs (e.g., the entire image, bounding boxes, or object points). These masks are passed to LaMa, a deep learning model that seamlessly restores masked regions using surrounding pixel information. LaMa generates natural background images, even for complex or large masked areas. The generated background images are then provided to Depth Anything, which calculates the depth information for each pixel to produce depth background images. Depth Anything estimates depth based on the physical position and distance of objects, creating depth images that remain unaffected by the facilities or lighting conditions of the pigpen environment. These depth background images effectively establish the RoI. We propose a new DOG image generation method, which involves converting RGB colors to the hue, saturation, value (HSV) color space and leveraging HSV-Value and HSV-Saturation information. In the HSV-Saturation space, white and black are defined as achromatic colors, and since most pigs have colors based on white or black, their HSV \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**No. of Sensors** & **No. of Pigs** & **Use Foundation Model** & **Test Unseen Image** & **Ref.** \\ \hline
1 & 9–18 & X & X & [37] \\ (Depth) & 10 & X & X & [32] \\ \hline
2 & 9 & X & X & [8] \\ (Infrared, & & & & \\ Depth) & 1 & X & X & [38] \\ \hline  & 6 & X & X & [39] \\  & 13 & X & X & [31] \\  & 23 & X & - & [40] \\
2 & 1 & X & X & [36] \\ (Color, & 9 & X & X & [41] \\ Depth) & 1 & X & - & [42] \\  & - & X & - & [43] \\  & 9 & X & - & [44] \\ \hline
3 & & & & \\ (Color, & 8 & X & X & [45] \\ Infrared, & & & & \\ Depth) & & & & \\ \hline
1 & & & & \\ (Color) & 23 & \(\Circuit\) & \(\Circuit\) & Proposed \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Summary of related works regarding pig, depth, detection. Saturation values are close to zero. This consistent representation of pigs' brightness in HSV-Saturation images, irrespective of their positions in the RGB image, allows the effective separation of foreground pixels that are otherwise difficult to distinguish using color information alone. However, HSV-Hue, which represents pure color information as an angle, was excluded because it is sensitive to changes in object position and lighting conditions, making it less reliable. This HSV-based approach helps address issues arising from complex lighting conditions and color similarities between objects and the background. For the HSV-Value and depth background images used in the image generation process, we apply Contrast-Limited Adaptive Histogram Equalization (CLAHE) [46]. CLAHE enhances contrast by uniformly distributing pixel values and adjusts histograms locally to overcome the limitations of global histogram equalization. This technique prevents noise amplification while effectively improving contrast. By applying CLAHE to both HSV-Value images and depth background images, the histograms are smoothed, and object shapes and boundaries become more distinct. Consequently, boundaries between objects and backgrounds, which are challenging to distinguish using HSV-Value images alone, can be effectively separated by combining these images with depth-based images for accurate RoI determination. Figure 2 illustrates the entire process proposed in this study. Given an input image, the first step is the RoI Setting Module, executed only once to generate the depth images of the input scene. The generated depth information establishes RoIs that effectively separate the foreground and background in a top-view fixed camera environment. Next, the DOG Generation Module takes the initialized depth background image and established RoIs from the RoI Setting Module as inputs to generate DOG images.