We present a new autofocusing method as a part of a general project to automatize a transmission microscope for inspection of cytological tissue. These images present several cell superpositions that lead to the appearance of false edges under defocus conditions. This means that some autofocusing algorithms, based on derivatives, may not work properly. The method that we propose allows us to solve this problem. The paper is divided in two parts. In the first we present a new focusing criterion, the dynamic focus criterion (DFC). It is computed by comparing (point to point) the gray-level values of two images instead of comparing the energy of the first or second derivatives. This allows us to avoid certain bad effects on the shape of the criterion function, which are due to the structure of the cytological images and the transmission of light. In the second part we propose an optimal search algorithm to find the best-focused image using the DFC. Optimality is given in terms of the number of lens movements. The algorithm considers not only the unimodal property, as the classical Fibonacci search does, but also the symmetry of the criterion function. Finally, some results on its performance are given.