Estimating the light pollution Now that we have roughly classified non-star pixels, we can fit our model for light pollution to the remaining background pixels. As mentioned before, we model light pollution within small patches of pixels as a linear gradient. Such a gradient has three parameters: Its brightness, its x-slope and its y-slope. Our goal now is to estimate these parameters so that the linear gradient best matches the input image. This problem is best known as Weighted Least Squares and is well-studied. We can write the optimal fit in terms of a set of linear equations (XTWX)β=XTWy, where y is the vector of input pixels, β are the parameters of our model, X is the feature matrix (pixel positions + a column of constant 1s) and W is a diagonal matrix containing our image mask. This will not make much sense unless you are familiar with linear regression (I won't go into the details), but just assume that this allows us to compute the optimal parameters. Arbitrary sized matrix math is inconvenient to implement, and I've opted to use the excellent Eigen matrix library to solve this system of equations. Once we have estimated the parameters β , we can go in the reverse direction: Evaluating Xβ retrieves the value of the model for all pixels in the patch.

视频信息