Abstract:Traditional focus measure algorithms typically convert color images into grayscale prior to processing, which inevitably leads to the loss of chromatic information and consequently reduces the accuracy of focus assessment. To address this limitation, this study proposes a focus measure algorithm based on spatial chromatic dispersion and color gradients. First, the Euclidean distances between color vectors of adjacent pixels within a local window in the RGB space are calculated to construct a set of pixel-wise chromatic differences, and the product of the sum and variance of this set is defined as the spatial chromatic dispersion. Second, a spatial correlation matrix is constructed using the gradient values of the RGB channels of the color image, and the trace of this matrix is adopted as the color gradient measure. Finally, the spatial chromatic dispersion and color gradient are modeled as the prior distribution and likelihood function, respectively, and a Gaussian posterior distribution is derived using Bayesian statistics to serve as the focus measure function.The proposed algorithm enhances the accuracy of focus evaluation for color images and accelerates peak response, while also improving discrimination in weak-texture regions and areas with limited color information. Experimental results show that, compared with several mainstream methods, the proposed algorithm achieves improvements of 9% and 15% in peak sensitivity, curve steepness, and flat-region fluctuation on simulated and real images, respectively. When applied to 3D reconstruction, the algorithm attains the best performance in terms of RMSE and CORR on simulated datasets, and the relative depth-value error on real images does not exceed 4.6%. These findings demonstrate that the proposed algorithm exhibits superior focus measurement performance and can significantly improve the accuracy of 3D reconstruction.