There are many impurities in the microscopic images of extracted microsporidia samples of Bombyx mori pebrine, and Bombyx mori pebrine with elliptical symmetric shape has certain fluidity and obvious stratification. Traditional focusing methods cannot accurately locate the main regions of microsporidia images, and the focusing effect is poor. On this basis, an automatic focusing method combining the microsporidia image features and the evaluation and determination of maximum gradient direction is proposed. First, the HSV color space with stable color information is used to extract the suspected positions of microsporidia targets, so that the interference of some impurities under complex backgrounds is removed and the redundancy of image content calculation is reduced. Then, combined with the light green features of Bombyx mori pebrine, the G-component gray image of microsporidia in the RGB color space is used to extract the significant gradient region. A dynamic focus window is constructed to accurately locate the target region and reduce the influence of microsporidia flow on the focus evaluation function and the bimodal interference caused by impurities. Finally, the maximum second-order difference is obtained through the four-dimensional gradient distribution, and the focus sharpness evaluation function is formulated to adapt to the microsporidia shape and improve the sensitivity of the focus function. The experiments show that under the dynamic window of microsporidia color gradient of different samples, the sharpness ratio and the highest sensitivity factor of the focus evaluation function proposed in this paper can reach 0.06341 and 0.95, respectively. It can meet the accurate and sensitive autofocus of microscopic images of color microsporidia samples under complex backgrounds.