## 3 Methodology
### Database Augmentation  
The collected thermal images were used to locate areas of moisture within the walls, while the visible images were employed to identify the locations of the red walls. However, due to the differences in resolution between the visible and thermal images, all images were cropped and resized prior to being input into the CNN model. This standardization step was essential to prevent the model from making erroneous predictions due to inconsistent image dimensions [22].  
Since CNN training requires a substantial amount of data, the standardized thermal images were further divided into 12 equal rectangular segments to increase the training sample size and improve model accuracy. Each segmented image measured 235 \(\times\) 235 pixels  
Figure 4: Enhancement of a visible image and an infrared thermal image. (**a**) Overlap and binarization of visible and infrared thermal images. (**b**) Contour map for an original image and the corresponding infrared thermal image.  
Figure 5: Comparison of infrared thermal images obtained before and after mask application. (**a**) Before mask application. (**b**) After mask application.  
and often contained a large portion of pure red wall or pure background. This method helped reduce the unsatisfactory training results caused by the compression or deformation of input data. The segmentation results are shown in Figure 6.  
To accurately identify whether the analyzed walls contained moisture, two CNN models were trained in this study. The first model was used to identify the presence of red walls in the visible images. When the presence of walls was confirmed, the second model identified whether the walls contained moisture in the thermal images. Because of the different requirements of these two CNN models, independent training image databases were required.  
The dataset used in this study included thermal images of red walls captured at the [PERSON] temple and the Lee's Ancestral Residence in Luzhou. It not only increased the amount of training data but also broadened the application of this method. As a result, the applicability of this method is not limited to the Confucian Temple but can also be generalized for detecting moisture in the red walls of other heritage structures.  
From the image databases for the CNN models, 80% and 20% of the images were designated for training and testing, respectively. The first set of images consisted of 4200 unenhanced red wall images and 2800 images without red walls. The second set of images consisted of 1500 images of moist wall areas and 2000 images of wall areas without moisture. The sample datasets for detecting red walls in the visible images and moisture in the thermal images are shown in Figure 7. Within the red wall dataset, images in which the red wall occupied only a minimal portion of the frame were categorized under the 'Without red wall' class.  
Figure 6: Segmentation results. (**a**) Visible image. (**b**) Infrared thermal image.  
A total of 5600 images were selected from the first group to serve as the dataset, ensuring a uniform distribution of images under different conditions. To increase the number of training samples, image rotation techniques were applied to the second group. Specifically, 500 red wall images were augmented by applying a small rotation of \(\pm 10^{\circ}\), as summarized in Table 1. This limited rotation range was chosen to mitigate issues such as data imbalance and overfitting. Randomized selection and random angle deflection were employed to ensure that the appearance probabilities of all samples were as evenly distributed as possible. Two examples of rotated images are shown in Figure 8.