3D color homography model for photo-realistic color transfer re-coding

Color transfer is an image editing process that naturally transfers the color theme of a source image to a target image. In this paper, we propose a 3D color homography model which approximates photo-realistic color transfer algorithm as a combination of a 3D perspective transform and a mean intensity mapping. A key advantage of our approach is that the re-coded color transfer algorithm is simple and accurate. Our evaluation demonstrates that our 3D color homography model delivers leading color transfer re-coding performance. In addition, we also show that our 3D color homography model can be applied to color transfer artifact fixing, complex color transfer acceleration, and color-robust image stitching.


Introduction
Color palette modification for pictures/frames is often required in professional photograph editing as well as the video postproduction.Artists usually choose a desired target picture as a reference and manipulate the other pictures to make their color palette similar to the reference.This process is known as photo-realistic color transfer.Figure 1 shows an example of photo-realistic color transfer between a target image and a source image.This color transfer process is a complex task that requires artists to carefully adjust for multiple properties such as exposure, brightness, white point, and color mapping.These adjustments are also interdependent, i.e., the alignment for a single property can cause the other previously aligned properties to become misaligned.Some artifacts due to nonlinear image processing (e.g., JPEG block edges) may also appear after color adjustment.
One of the first photo-realistic color transfer methods was introduced by Reinhard et al. [23].Their method proposed that the mean and variance of the source image, in a specially chosen color space, should be manipulated to B Han Gong h.gong@uea.ac.uk, gong@fedoraproject.org 1 School of Computing Sciences, University of East Anglia, Norwich, UK 2 School of Informatics, University of Edinburgh, Edinburgh, UK match those of a target.More recent methods [1,16,[19][20][21] might adopt more aggressive color transfers-e.g., color distribution force matches [19,20]-and yet, these aggressive changes often do not preserve the original intensity gradients and new spatial type artifacts may be introduced into an image (e.g., JPEG blocks become visible or there is false contouring).In addition, the complexity of a color transfer method usually leads to longer processing time.To address these issues, previous methods [11,13,18] were proposed to approximate the color change produced by a color transfer, such that an original complicated color transfer can be re-formulated as a simpler and faster algorithm with an acceptable level of accuracy and some introduced artifacts.
In this paper, we propose a simple and general model for re-coding (approximating) an unknown photo-realistic color transfer which provides leading accuracy and the color transfer algorithm can be decomposed into meaningful parts.Our model is extended from a recent planar color homography color transfer model [11] to the 3D domain, as opposed to the original 2D planar domain.In our improved model, we decompose an unknown color transfer into 3D color perspective transform and mean intensity mapping components.Based on [11], we make two new contributions: (1) a 3D color mapping model that better re-codes color change by relating two homogeneous color spaces and (2) a monotonic mean intensity mapping method that prevents artifacts without adding unwanted blur.Our experiments show significant improvements in color transfer re-coding accuracy.We Throughout the paper, we denote the source image by I s and the original color transfer result by I t .Given I s and I t , we re-code the color transfer with our color homography model which approximates the original color transfer from I s to I t .Figure 1 shows the pipeline of our color transfer decomposition.
Our paper is organized as follows.We review the leading prior color transfer methods and the previous color transfer approximation methods in Sect. 2. Our color transfer decomposition model is described in Sect.3. We present a color transfer re-coding method for two corresponding images in Sect. 4. In addition, we demonstrate its applications in Sect. 5. Finally, we conclude in Sect.6.

Background
In this section, we briefly review the existing work on photorealistic color transfer, the methods for re-coding such a color transfer, and the concept of Color Homography.

Photo-realistic color transfer
Example-based color transfer was first introduced by Reinhard et al. [23].Their method aligns the color distributions of two images in a specially chosen color space via 3D scaling and shift.Pitie et al. [19,20] proposed an iterative color transfer method that distorts the color distribution by random 3D rotation and per-channel histogram matching until the distributions of the two images are fully aligned.This method makes the output color distribution exactly the same as the target image's color distribution.However, the method introduces spatial artifacts.By adding a gradient preservation constraint, these artifacts can be mitigated or removed at the cost of more blurry artifacts [20].Pouli and Reinhard [21] adopted a progressive histogram matching in L*a*b* color space.Their method generates image histograms at different scales.From coarse to fine, the histogram is progressively reshaped to align the maxima and minima of the histogram, at each scale.Their algorithm also handles the difference in dynamic ranges between two images.Nguyen et al. [16] proposed an illuminant-aware and gamut-based color transfer.They first eliminate the color cast difference by a whitebalancing operation for both images.A luminance alignment is later performed by histogram matching along the "gray" axis of RGB.They finally adopt a 3D convex hull mapping to limit the color-transferred RGBs to the gamut of the target RGBs.Other approaches (e.g., [1,25,28]) solve for several local color transfers rather than a single global color transfer.As most non-global color transfer methods are essentially a blend of several single color transfer steps, a global color transfer method is extendable for multi-transfer algorithms.and naturalness.Pitie et al. [18] proposed a color transfer approximation by a 3D similarity transform (translation + rotation + scaling) which implements a simplification of the earth mover's distance.By restricting the form of a color transfer to a similarity transform model, some of the generality of the transfer can be lost such that the range of color changes it can account for is more limited.In addition, a color transfer looks satisfying only if the tonality looks natural and this is often not the case with the similarity transformation.Ilie and Welch [13] proposed a polynomial color transfer which introduces higher-degree terms of the RGB values.This encodes the non-linearity of color transfer better than a simple 3×3 linear transform.However, the nonlinear polynomial terms may over-manipulate a color change and introduce spatial gradient artifacts.Similarly, this method also does not address the tonal difference between the input and output images.Gong et al. [11] proposed a planar color homography model which re-codes a color transfer effect as a combination of 2D perspective transform of chromaticity and shading adjustments.Compared with [18], it requires less parameters to represent a non-tonal color change.The model's tonal adjustment also further improves color transfer re-coding accuracy.However, the assumption of a 2D chromaticity distortion limits the range of color transfer it can represent.Their [11] tonal adjustment (mean intensity-to-shading mapping) also does not preserve image gradients and the original color rank.Another important work is probabilistic moving least squares [12] which calculates a largely parameterized transform of color space.Its accuracy is slightly better than [13].However, due to its high complexity, it is unsuitable for real-time use.In this paper, we only benchmark against the color transfer re-coding methods with a real-time performance.

2D color homography
The color homography theorem [7,8] shows that chromaticities across a change in capture conditions (light color, shading, and imaging device) are a homography apart.Suppose that we have an RGB vector ρ = [R, G, B] , its r and g chromaticity coordinates are written as r = R/B, g = G/B which can be interpreted as a homogeneous coordinate vector c and we have: when the shading is uniform and the scene is diffuse, it is well known that across a change in illumination or a change in device, the corresponding RGBs are, to a reasonable approximation, related by a 3 × 3 linear transform H 3×3 : where ρ is the corresponding RGBs under a second light or captured by a different camera [14,15].Due to different shading, the RGB triple under a second light is written as where H 3×3 here is a color homography color correction matrix, α denotes an unknown scaling.Without loss of generality, let us interpret c as a homogeneous coordinate, i.e., assume its third component is 1.Then, rg chromaticities c and c are a homography apart.
The 2D color homography model decomposes a color change into a 2D chromaticity distortion and a 1D tonal mapping, which successfully approximates a range of physical color changes.However, the degrees of freedom of a 2D chromaticity distortion may not accurately capture more complicated color changes applied in photograph editing.

3D color homography model for photo-realistic color transfer re-coding
The color homography theorem reviewed in Sect.2.3 states that the same diffuse scene under an illuminant (or camera) change will result in two images whose chromaticities are a 2D (planar) homography apart.The 2D model works best for RAW-to-RAW linear color mappings and can also approximates the nonlinear mapping from RAW to sRGB [8].In this paper, we extend the planar color homography color transfer to the 3D spatial domain.A 3D perspective transformation in color may be interpreted as a perspective distortion of color space (e.g., Fig. 2).Compared with the 2D homography model, the introduction of a 3D perspective transform can model a higher degree of non-linearity in the color mapping.
We propose that a global color transfer can be decomposed into a 3D perspective transform and a mean intensity alignment.
We start with the outputs of the previous color transfer algorithms.We represent a 3D RGB intensity vector by its 4D homogeneous coordinates (i.e., appending an additional element "1" to each RGB vector).Assuming we relate I s to I t with a pixel-wise correspondence, we represent the RGBs of I s and I t as two n × 3 matrices R s and R t , respectively, where n is the number of pixels.We also denote their corresponding n×4 homogeneous RGB matrices as Ṙs and Ṙt .For instance, Ṙs can be converted to R s by dividing its first 3 columns by its 4th column.Our 3D color homography color transfer model is proposed as: where D is a n ×n diagonal matrix of scalars (i.e., exposures, but only used for estimating H 4×4 ) and H 4×4 is a 4 × 4 perspective color space mapping matrix, h() is a function that converts a n × 4 homogeneous RGB matrix to a n × 3 RGB matrix (i.e., it divides the first 3 columns of Ṙs by its 4th column and removes the 4th column such that R s = h( Ṙs )), D is another n × n diagonal matrix of scalars (i.e., shadings) for mean intensity mapping.A color transfer is decomposed into a 3D homography matrix H 4×4 and a mean intensity mapping diagonal matrix D .The effect of applying the matrix H is essentially a perspective color space distortion (e.g., Fig. 2).
That is, we have a homography for RGB colors (rather than just chromaticities -(R/B, G/B)).D adjusts mean intensity values (by modifying the magnitudes of the RGB vectors) to cancel the tonal difference between an input image and its color-transferred output image (e.g., the right half of Fig. 1).

Image color transfer re-coding
In this section, we describe the steps for decomposing a color transfer between two registered images into the 3D color homography model components.

Perspective color space mapping
We solve for the 3D homography matrix H 4×4 in Eq. 4 by using alternating least squares (ALS) [9] as illustrated in Algorithm 1 where i indicates the iteration number.In each Algorithm 1: Homography from alternating least squares iteration, Step 4 (Algorithm 1) keeps D fixed (which was updated in Step 5 of a previous iteration) and finds a better H 4×4 .
Step 5 finds a better D using the updated H 4×4 fixed.The minimization in Steps 1, 4, and 5 are achieved by linear least squares.After these alternating estimation steps, we get a decreasing evaluation error for Ṙi s − Ṙi−1 s F .The assured convergence of ALS has been discussed in [26].Practically, we may limit the number of iterations to n = 20.(Empirically, the error is not significant after 20 iterations.)

Mean intensity mapping
The tonal difference between an original input image and the color-transferred image is caused by the nonlinear operations of a color transfer process.We cancel this tonal difference by adjusting mean intensity (i.e., scaling RGBs by multiplying D in Eq. 5).To determine the diagonal scalars in D , we first propose a universal mean intensity-to-mean intensity mapping function g() which is a smooth and monotonic curve fitted to the per-pixel mean intensity values (i.e., mean values of RGB intensities) of the two images.As opposed to the unconstrained mean intensity-to-shading mapping adopted in [11], we enforce monotonicity and smoothness in our optimization which avoids halo-like artifacts (due to sharp or non-monotonic tone change [6]).The mapping function g is fitted by minimizing the following function: subject to g (t) ≥ 0 and 0 ≤ g(t) ≤ 1. ( where the first term minimizes the least-squares fitting error and the second term enforces a smoothness constraint for the fitted curve.x and y are assumed in [0, 1].The curve is smoother when the smoothness factor p is larger ( p = 10 −5 by default).x and y are the input and reference mean intensity vectors.The mapping function g() is implemented as a lookup table which is solved by quadratic programming [4].
Let the operator diag(x) return a diagonal matrix with components of x along its diagonal.Given the estimated mean intensity mapping function g(), the diagonal scalar matrix D (in Eq. 5) is updated as follows: where b is the input mean intensity vector of the 3D color space-mapped RGB values (i.e., h( Ṙs H 4×4 )).Because this

Our Initial Approximation
After Noise Reduction Output of 2D-H [11] Fig. 3 Minor noise reduction: Some JPEG block artifacts of our initial approximation are reduced via mean intensity mapping noise reduction step.Compared with our final approximation result (middle), the output of [11] contains significant blur artifacts at the boundary of the hill.Row 2 shows the magnified area in Row 1. Row 3 shows the shading image I D of the magnified area step only changes the magnitude of an RGB vector, the physical chromaticity and hue are preserved.

Mean intensity mapping noise reduction
Perhaps because of the greater compression ratios in images and videos, we found that, even though the mean intensity is reproduced as a smooth and monotonic tone curve, some minor spatial artifacts could-albeit rarely-be introduced.
We found that the noise can be amplified in the mean intensity mapping step and the component D (in Eq. 5) absorbs most of the spatial artifacts (e.g., JPEG block edges).To reduce the potential gradient artifacts, we propose a simple noise reduction.Because D scales each pixel individually, we can visualize D as an image denoted as I D .We remove the spatial artifacts by applying a joint bilateral filter [17] which spatially filters the scale image I D guided by the source image I s such that the edges in I D are similar to the edges in the mean intensity channel of I s .Figure 3 shows the effect of the monotonic smooth mean intensity mapping and its mapping noise reduction.Although it is often not necessary to apply this noise reduction step, we have always included it as a "safety guarantee."

Results
In our experiments, we assume that we have an input image and an output produced by a color transfer algorithm.
Because the input and output are matched (i.e., they are in perfect registration), we can apply Algorithm 1 directly.
In the experiments which follow, we call our method-3D homography color transform + mean intensity mapping-"3D-H."Similarly, the 2D homography approach for color transfer re-coding [11] is denoted as "2D-H."We first show some visual results of color transfer approximations of [16,20,21,23] in Fig. 4. Our 3D color homography model offers a visually closer color transfer approximation.
Although a public dataset for color transfer re-coding was published in [11], it contains a limited sample size.In this work, we use a new dataset 1 In Table 1, we quantitatively evaluate the approximation accuracy of the 3 state-of-the-art algorithms [11,13,18] by the error between the approximation result and the original color transfer result.The results are the averages over the 200 test images.The method [13] is tested by using a common second-order polynomial (which avoids over-fitting).We adopt PSNR (peak signal-to-noise ratio) and SSIM (structural similarity) [27] as the error measurements.Acceptable values for PSNR and SSIM are usually considered to be, respectively, over 20 dB and 0.9.Table 1 shows that 3D-H is generally better than the other compared methods for both PSNR and SSIM metrics.To further investigate the statistical significance of the evaluation result, we run a one-way ANOVA to verify that the choice of our model has a significant and positive effect on the evaluation metrics (i.e., PSNR and SSIM).In our test, we categorize all evaluation numbers into four groups according to associated color transfer re-coding method.Table 2 shows the post hoc tests for one-way ANOVA where the choice of color transfer approximation method is the only variable.We obtained the overall p-values < 0.001 for both PSNR and SSIM which indicate the choice of color transfer re-coding method has a significant impact on the color transfer approximation result.In addition, we run a post hoc analysis and found near 0 p-values when comparing 3D-H with all 3 other methods.This further confirms that the difference in performance of 3D-H is significant.Our test also shows that the difference between 2D-H [11] and Poly [13] is not significant.Our 3D color homography model produces the best result overall.

Applications
In this section, we demonstrate three applications of our color transfer re-coding method.

Color transfer acceleration
More recent color transfer methods usually produce higherquality outputs, however, at the cost of more processing

Table 1 Mean errors between the original color transfer result and its approximations by 4 popular color transfer methods
Nguyen [16] Pitie [20] Pouli [21] Reinhard [23] PSNR (peak signal-to-noise ratio) The best results are made bold time.Methods that produce high-quality images and are fast include the work of Gharbi et al. [10] who proposed a general image manipulation acceleration method-named transform recipe (TR)-designed for cloud applications.
Based on a downsampled pair of input and output images, their method approximates the image manipulation effect according to changes in luminance, chrominance, and stack levels.Another fast method by Chen et al. [3] approximates the effect of many general image manipulation procedures by convolutional neural networks (CNNs).While their approach significantly reduces the computational time for some complex operations, it requires substantial amounts of samples for training a single image manipulation.In this subsection, we demonstrate that our re-coding method can be applied as an alternative to accelerate a complex color transfer by approximating its color transfer effect at a lower scale.We approximate the color transfer in the following steps: (1) We supply a thumbnail image (40 × 60 in our experiment) to the original color transfer method and obtain a thumbnail output; (2) Given the pair of lower-resolution input and output images, we estimate a color transfer model that approximates the color transfer effect; (3) We then process the higherresolution input image by using the estimated color transfer model and obtain a higher-resolution output which looks very close to the original higher-resolution color transfer result without acceleration.
In our experiment, we choose two computationally expensive methods [16,20] as the inputs and we compare our performance (MATLAB implementation) with a state-ofthe-art method TR [10] (Python implementation).Figure 5 shows the output comparisons between the original color transfer results and the acceleration results.The results indicate that our re-coding method can significantly reduce the computational time (25× to 30× faster depending on the speed of original color transfer algorithm and the input image resolution) for these complicated color transfer methods while preserving color transfer fidelity.Compared with TR [10], our method produces similar quality of output for global color transfer approximation, however, at a much reduced cost of computation (about 10× faster).Although TR [10] is less efficient, it is also worth noting that TR supports a wider range of image manipulation accelerations which include non-global color change.

Color transfer artifact reduction
Color transfer methods often produce artifacts during the color matching process.Here we show that our color transa Original Input b Original Output by [20] Total Time: 0.29s App.Time: 0.05s PSNR: 32.00 Time: 16.04s Time: 8.86s d [20] Accelerated by 3D-H e Original Output by [16] Total Time: 6.63s App.Time: 6.39s PSNR: 34.00Total Time: 0.62s App.Time: 0.05s PSNR: 32.00Total Time: 6.46s App.Time: 5.89s PSNR: 31.20 c [20] Accelerated by TR [22] g [16] Accelerated by 3D-H f [16] Accelerated by TR [22] Fig. 5 Color transfer acceleration.The color transfers [16,20] of an original image (a) are accelerated by our 3D-H color transfer re-coding method and a state-of-the-art method transform recipe (TR) [10] fer re-coding method can be applied as an alternative to reduce some undesirable artifacts (e.g., JPEG compression block edges).As discussed in Sect.4.3, the color transfer artifacts are empirically "absorbed" in the shading scale component.Therefore, we can simply filter the shading scale layer by using the de-noising step described in Sect.4.3.
Figure 6 shows our artifact reduction result where we also compare with a state-of-the-art color transfer artifact reduction method-transportation map regularization (TMR) [22].
Compared with the original color transfer output, our processed result better preserves its contrast and color similarity (e.g., the grass).Meanwhile, it also removes the undesirable artifacts.And, depending on an individual user's personal preference, the result of TMR could also be preferred since TMR makes the contrast of its result more similar to the original input.While one of our goals is to make the processed colors close to the original output image's colors, it is also possible to transfer the details of the original input image to our result using the detail transfer method suggested in [5].The result of this input detail recovery is shown in Figure 6e.

Color-robust image stitching
The input images for image stitching are not always taken by the same camera or under the same illumination con-ditions.The camera's automatic image processing pipeline also modifies the colors.Direct image stitching without color correction may therefore leave imperfections in the final blending result.Since the color change between images of different views is unknown but photo-realistic, our color transfer approximation model can be applied to address this color inconsistency problem. Figure 7 shows an example of a color-robust image stitching using our color transfer re-coding method where 2 input images taken by 2 different cameras and in different illuminations are supplied for image stitching.In our color-robust procedure, we first register these two images and find the overlapping pixels.With the per-pixel correspondences, we estimate a 3D color homography color transfer model that transfers the colors of the first image to the second image's.We then apply the estimated color transfer model to correct the first image.Finally, the corrected first input image and the original second image are supplied to the image stitching software AutoStitch [2].
Although the multi-band blending proposed in [2] provides a smooth transition at the stitching boundary, the color difference between the two halves is still noticeable (especially for the sky and tree colors) in the original stitching result.After our color alignment process, the colors of the two halves look more homogeneous.We also compare our method with a local color correction method-gain compensation [2].

Conclusion
In this paper, we have shown that a global color transfer can be approximated by a combination of 3D color space mapping and mean intensity mapping.Our experiments show that the proposed color transfer model approximates well for many photo-realistic color transfer methods as well as unknown global color change in images.We have demonstrated three applications for color transfer acceleration, color transfer artifact reduction, and color-robust image stitching.
a 1000-entry lookup table (LUT) that approximates the mean intensity mapping function g().We first quantize input mean intensity values x into 1000 uniform levels distributed within [0, 1].To construct a deterministic one-to-one mean intensity mapping, we have two issues to address before the actual optimization: (1) Among the training mean intensity pairs, it is likely that each unique input mean intensity level x i (where i is an index) is mapped to more than one reference output mean intensity values.To address this, we define the mean of all reference output mean intensity values of x i as a unique reference output mean intensity value y i for x i .( 2) Each unique input level x i may have a different number of (or none) input training data pairs.To balance data fitness in the later weighted least-squares optimization, we construct a weight vector w whose element w i is the count of training data associated with x i which can be 0 if there are no data associated with the quantization level.(See Fig. 1 for an example.)Suppose that the elements of the 1000-vectors x and y are simultaneously sorted in an ascending order based on the elements of x (i.e., x i < x i+1 ), we can approximate the minimization by finite differentiation and rewrite Eq. 6 as: ∀i ∈ {2, 3, . . .n} g(x i ) − g(x i−1 ) ≥ 0 0 ≤ g(x i−1 ), g(x i ) ≤ 1 where g (x i ) ≈ g(x i )−g(x i−1 ) x i −x i−1 = g(x i )−g(x i−1 ) (n−1) −1 n = 10 3 .(8) where n is the number of unique input mean intensity values x (for training).Further, since the mean intensity mapping is a positive-to-positive number mapping, we can define the mean intensity mapping function as g(x i ) = α i x i where α i is a positive scalar of a scalar vector α.We can then rewrite Eq. 8 in matrix multiplication form as: In Eq. 9, D n is defined as a (n − 1) × (n) sparse forward difference matrix (where n is a variable size), 0 and 1 are, respectively, a (n − 1) zero vector and a (n − 1) one vector, d g 1 and d g 2 are, respectively, the first-order and second-order finite difference vectors of g(), with respect to x.Finally, we convert the minimization function of Eq. 9 into a quadratic form:  (10) where M is a sparse Hessian matrix and f is a linear term.With the pre-computed M, f , and the inequality conditions, we can apply quadratic programming to solve for α.The mapped one-to-one deterministic output mean intensity value is computed as diag(x)α.

Implementation details
We implemented the proposed algorithm in MATLAB.In ALS (Algorithm 1), we exclude the undersaturated pixels with zero RGBs as they contain no useful color information.Practically, we also limit the maximum iteration number of ALS to 20, beyond which we do not find any significant fidelity improvement.

Fig. 1
Fig.1Pipeline of our color transfer decomposition.The "target" image was used by the "original color transfer" algorithms to produce the "original color transfer" output image, but it is not used by the proposed color transfer re-coding algorithm.The orange dashed line divides the pipeline into two steps: (1) color space mapping: The RGBs of the source image (drawn as red edge circles) and the original color transfer image (by[16] with the target image as the reference, black edge cir-

4 Fig. 2
Fig.2Homogeneous color space mapping.The left 3 homogeneous RGB cubes are equivalent (up to a scale).The left RGB space cubes can be mapped to the right by a 4 × 4 3D homography transform H

Fig. 4
Fig. 4 Visual result of 4 color transfer approximations (rightmost 4 columns).The original color transfer results are produced by the methods cited at the top right of the images in the first column.The original

Fig. 6
Fig.5 Color transfer acceleration.The color transfers[16,20] of an original image (a) are accelerated by our 3D-H color transfer re-coding method and a state-of-the-art method transform recipe (TR)[10].The top right labels in (b) and (e) show the original color transfer time.The

Fig. 7
Fig. 7 Color-robust image stitching.a, b are the original images taken by 2 different cameras.c is the color-transferred results from Image 2 to Image 1. d shows the original image stitching result without color trans-

Table 2
Post hoc tests for one-way ANOVA on errors between the original color transfer result and its approximations

a
Original Image 1 b Original Image 2 c Image 1 to Image 2