Combinations of microscopy and molecular techniques to detect, identify and characterize microorganisms in environmental and medical samples are widely used in microbial ecology and biofilm research. The scope of these methods, which include fluorescence in situ hybridization (FISH) with rRNA-targeted probes, is extended by digital image analysis routines that extract from micrographs important quantitative data. Here we introduce daime (digital image analysis in microbial ecology), a new computer program integrating 2-D and 3-D image analysis and visualization functionality, which has previously not been available in a single open-source software package. For example, daime automatically finds 2-D and 3-D objects in images and confocal image stacks, and offers special functions for quantifying microbial populations and evaluating new FISH probes. A novel feature is the quantification of spatial localization patterns of microorganisms in complex samples like biofilms. In combination with '3D-FISH', which preserves the 3-D structure of samples, this stereological technique was applied in a proof of principle experiment on activated sludge and provided quantitative evidence that functionally linked ammonia and nitrite oxidizers cluster together in their habitat. This image analysis method complements recent molecular techniques for analysing structure-function relationships in microbial communities and will help to characterize symbiotic interactions among microorganisms.