An autofocus is a desirable feature of an endoscope, because it relieves the user from performing a task which can be automated and thereby prevents unnecessary interruptions in the work to be performed. Autofocusing is in general best achieved by an active system, i.e., on the basis of a distance measurement. Yet, in handheld medical endoscopes such a method is unsuited because of the added weight associated with the necessary electromechanical components. Autofocusing should rather be performed passively, furthermore, in applications which are particularly critical with respect to safety, e.g., in the eye, a stable and reliable operation in real time and without interruption is necessary. Passive autofocus strategies applied to date and known to the authors lead however to algorithms which are either too slow for a real time implementation and/or are influenced by the structure of the object which is to be brought into focus. Accordingly, a new autofocus procedure has been developed which exhibits a stable and reliable operation in real time under all circumstances of interest. It is based on the squared differences of the intensity of adjacent points in both dimensions of a plane image (Square Plane Sum Modulus Difference, SPSMD) and as such particularly suitable for digital camera systems and real-time needs (typically, 30 evaluations per second on an image of 1024 x 1024 pixels). The SPSMD criterion is more sensitive, has a larger SNR than other focus criteria known to the authors and exhibits in particular no secondary extrema which could adversely affect proper focusing. As it includes intensity differences in both (perpendicular) directions in the image plane, it is essentially independent of image structures.