An imaging system for imaging a sample in a sample holder, the imaging system comprising: - a camera subsystem comprising an image sensor and magnification optics and configured to image the sample via the magnification optics; - a projection subsystem comprising a light source and an astigmatic optical element and configured to project a two-dimensional pattern onto the sample holder via the astigmatic optical element and via the magnification optics; - an actuator configured to adjust a distance between the sample holder and the magnification optics; and - a processor subsystem comprising: - a camera interface configured to receive image data acquired by the camera subsystem; - an actuator interface configured to control the actuator; - a memory comprising instruction data representing a set of instructions; and - a processor configured to communicate with the camera interface and the memory and to execute the set of instructions, wherein the set of instructions, when executed by the processor, cause the processor to: - determine a measure of sharpness (412, 422) of the two-dimensional pattern along a first axis in the image data; - determine a measure of sharpness (414, 424) of the two-dimensional pattern along a second axis in the image data which is orthogonal to the first axis; - determine a difference between the measures of sharpness along the first axis and the second axis, and based on the difference, determine a magnitude and direction of defocus of the camera subsystem with respect to the sample holder; and - based on the magnitude and/or direction of defocus, control the actuator via the actuator interface to bring the sample and/or sample holder into focus. - a camera subsystem comprising an image sensor and magnification optics and configured to image the sample via the magnification optics; - a projection subsystem comprising a light source and an astigmatic optical element and configured to project a two-dimensional pattern onto the sample holder via the astigmatic optical element and via the magnification optics; - an actuator configured to adjust a distance between the sample holder and the magnification optics; and - a processor subsystem comprising: - a camera interface configured to receive image data acquired by the camera subsystem; - an actuator interface configured to control the actuator; - a memory comprising instruction data representing a set of instructions; and - a processor configured to communicate with the camera interface and the memory and to execute the set of instructions, wherein the set of instructions, when executed by the processor, cause the processor to: - determine a measure of sharpness (412, 422) of the two-dimensional pattern along a first axis in the image data; - determine a measure of sharpness (414, 424) of the two-dimensional pattern along a second axis in the image data which is orthogonal to the first axis; - determine a difference between the measures of sharpness along the first axis and the second axis, and based on the difference, determine a magnitude and direction of defocus of the camera subsystem with respect to the sample holder; and - based on the magnitude and/or direction of defocus, control the actuator via the actuator interface to bring the sample and/or sample holder into focus. - a camera interface configured to receive image data acquired by the camera subsystem; - an actuator interface configured to control the actuator; - a memory comprising instruction data representing a set of instructions; and - a processor configured to communicate with the camera interface and the memory and to execute the set of instructions, wherein the set of instructions, when executed by the processor, cause the processor to: - determine a measure of sharpness (412, 422) of the two-dimensional pattern along a first axis in the image data; - determine a measure of sharpness (414, 424) of the two-dimensional pattern along a second axis in the image data which is orthogonal to the first axis; - determine a difference between the measures of sharpness along the first axis and the second axis, and based on the difference, determine a magnitude and direction of defocus of the camera subsystem with respect to the sample holder; and - based on the magnitude and/or direction of defocus, control the actuator via the actuator interface to bring the sample and/or sample holder into focus.