# HSVNet: Reconstructing HDR Image from a Single Exposure LDR Image with CNN
## 3 Method
### Loss Function  
A normal Mean Absolute Error (MAE) is applied to \(S\) and \(V\) channels. Unlike Saturation and Value, Hue is angular data. When MAE is directly applied to the \(H\) channel, the model cannot predict the color around the red correctly. Even though both \(0^{\circ}\) and \(360^{\circ}\) indicate the same red color, MAE gives the highest penalty when predicted \(H\) is \(0^{\circ}\) and target \(H\) is \(360^{\circ}\) or vice versa. Therefore, the red color might converge to the average value of \(0^{\circ}\) and \(360^{\circ}\). As shown in Figure 3, the predicted images with a MAE \(H\) loss may have local artifacts, e.g., the red color is predicted as blue.  
Therefore, we develop a customized loss function, \(L_{h}\), for the \(H\) channel. First, we define a simple wrap-around distance, \(d_{h}\), which is the difference between the predicted value and the target value in polar coordinates. \(d_{h}\) is the angle of the shortest arc between two \(H\) values on a unit circle. As shown in Figure 4, the shortest arc angle between \(H_{1}\) and \(H_{2}\) can be represented as \(|H_{2}-H_{1}|\) or \(1-|H_{2}-H_{1}|\). Since we take the shortest path, the minimum value is selected.  
\[d_{h}(H_{1},H_{2})=Min(|H_{2}-H_{1}|,1-|H_{2}-H_{1}|) \tag{2}\]  
Figure 2: Our HSVNet architecture with U-net.  
Figure 5a shows a Hue space of HSV color [35], where the angle presents the Hue. In this space, three primary colors (Red, Green, and Blue) are separated by and three secondary colors (Yellow, Cyan, and Magenta) are located \(60^{\circ}\) from primaries. As a result, color changes largely every \(60^{\circ}\). For this reason, if the wrap-around distance is over 60 degrees, we assign the maximum penalty to prediction in the \(H\) loss function. In human eyes, we perceive that both cyan and green are far from red to a similar extent, even though green is closer to red in the Hue space model theoretically. Therefore, not directly applying wrap-distance to \(L_{h}\), we set the maximum penalty if \(d_{h}\) is over \(1/6\) (=\(60^{\circ}/360^{\circ}\)) (see Figure 5b), which is a modified ramp function.  
Figure 4: (**left**) Wrap-around distance loss (\(d_{h}(H_{1},H_{2})\)). (**right**) Plot of \(d_{h}\).  
Figure 3: Comparison of simple distance loss (MAE) to wrap-around distance loss. All HDR images are tone-mapped in this paper.  
Finally, \(L_{h}\), \(L_{s}\), and \(L_{v}\) are defined as  
\[L_{h} =\frac{1}{N}{\sum}M_{h}Min(6d_{h}(\hat{y}_{h},y_{h}),1) \tag{3}\] \[L_{s} =\frac{1}{N}{\sum}M_{s}|\hat{y}_{s}-y_{s}|\] (4) \[L_{v} =\frac{1}{N}{\sum}M_{v}|\hat{y}_{v}-y_{v}| \tag{5}\]  
\[L=L_{h}+L_{s}+L_{v} \tag{6}\]  
where \(L\) is a loss function with channel \(h\), \(s\), and \(v\), \(M\) is a mask with channel \(h\), \(s\), and \(v\), \(N\) is the number of pixels, \(\hat{y}\) is estimation, and \(y\) is ground truth. The total loss function \(L\) is the sum of \(L_{h}\), \(L_{s}\), and \(L_{v}\). Each mask is applied to the corresponding channel in the loss function. We recognize that there are two distinct regions where \(H\), \(S\), or \(V\) are differently important to the training. Therefore, the mask applied to the loss function contributes to the better quality of output by adaptively focusing on crucial regions during the training. As Figure 6 shows, the HDR images predicted with the mask are more similar to the ground truth than those without the mask. The details about the mask are discussed in Section 3.3.