# Diffusion-Denoising Process with Gated U-Net for High-Quality Document Binarization
## 3 Method
### Gated U-Net in the Latent Space  
We have designed the denoising network using a gated U-Net architecture that incorporates a fully gated convolution to facilitate the detailed extraction and separation of the text and background regions. The U-Net architecture [10] leverages both the local and global features by combining the extraction of high-dimensional features with low-dimensional features through skip connections between the upsampling and downsampling stages. The gated convolution, as introduced in [22], represents a convolutional operation that integrates a dynamic feature selection mechanism capable of learning features in each channel at every spatial location. In contrast to a traditional convolution, which applies the same filter to all spatial positions, a gated convolution multiplies each spatial position in the feature map by a distinct weight, referred to as a gating value. This gating value distinguishes each position as either valid or invalid. As it traverses through the layer, the gating value places more emphasis on the text and text boundary regions, assuming values between 0 and 1 depending on each spatial location. Therefore, by passing the gating value of the feature map calculated in the previous layer to the next layer, it is possible to continuously provide a guide on the valid location. In the present study, the valid location means the text and the text boundary regions. In a specific region \((x,y)\) of a specific channel, the gated convolution can be formulated as follows:  
\[Gating_{x,y}=W_{g}\cdot I, \tag{5}\]  
\[Feature_{x,y}=W_{f}\cdot I, \tag{6}\]\[O_{x,y}=\phi(Feature_{x,y})\odot\sigma(Gating_{x,y}), \tag{7}\]  
where \(W_{g}\) and \(W_{f}\) are trainable convolution filters for extracting gating values and features, respectively, and \(I\) refers to an input feature map. \(\sigma\) is the sigmoid function, and \(\phi\) is the nonlinear activation function. Therefore, the final output \(O_{x,y}\) is determined through element-wise multiplication of the value obtained by applying the sigmoid function to the gating value and the value acquired by applying activation to the extracted feature value. By applying the sigmoid function to the gating value and subsequently multiplying it with the original feature, we ascertain the probability of a valid location. We use this gated convolution method to build a denoising network. Within the denoising process, we have designed the network to meticulously extract text regions by incorporating information pertaining to both the text itself and the text boundary regions. The denoising network has a U-Net architecture and uses a gated convolution in the downsampling and upsampling processes. All downsampling processes involve a gated convolution, whereas the upsampling process entails upscaling via a scale factor followed by another downsampling step. Consequently, the denoising network can be conceptualized as a fully gated convolution. Moreover, we use skip connections between upsampling and downsampling to facilitate information sharing. In the latent space, the gated U-Net effectively discriminates between the text and background regions, preserving each region by continuously incorporating trainable gating values as guides. Maximizing the effectiveness of a gated U-Net, comprising a fully gated convolution solely through the loss of existing diffusion models that provide training guidance based on the distribution of the latent vector, can be challenging. Hence, we introduce a pixel-level loss (\(L_{pix}\)) to enhance text-region extraction and facilitate effective updating of the gating values. \(L_{pix}\) calculates the disparity between the output of the decoder at a specific time step and the ground truth in the pixel space. We incorporate two noteworthy pixel-level losses to refine the difference between \(\hat{y}\), the output of the denoising network, and the ground truth \(y\) at a specific time step. The first is the binary cross-entropy loss for binary value classification at the pixel level.