Automatic gain control is provided for a confocal imaging system to
improve the quality of images produced by the system. The confocal
imaging system utilizes an illumination source, such as a laser, to
produce illumination which enables imaging of an object. The automatic
gain control is provided by an automatic gain controller which receives a
raster scan video of two-dimensional frames of images from the confocal
imaging system, converts the raster scan video into pixels, where each
pixel has a brightness value, and then counts, in each frame, the number
of pixels which are too bright, the number of pixels which are too dim,
and the total number of pixels. After each frame is received, the laser
of the confocal imaging system is controlled in accordance with signal(s)
produced by the automatic gain controller, whereby the power to the
illumination source is reduced when the number of pixels too bright
exceeds a number representing a first percentage of the total pixels of
the frame, and the number of pixels too dim is greater than a number
representing a second percentage of the total pixels of the frame, and
the power of the illumination source is increased when the number of
pixels too dim is less than the number representing the second percentage
of the total pixels of the frame, and the number of pixels too bright in
the image is less than the number representing the first percentage of
the total pixels of the frame. The automatic gain controller may be
operative over either the entire frame of the image, or a rectangular
region in the image.