A Bayesian approach is presented for detecting and characterizing the signal from discrete objects embedded in a diffuse background. The approach centres around the evaluation of the posterior distribution for the parameters of the discrete objects, given the observed data, and defines the theoretically optimal procedure for parametrized object detection. Two alternative strategies are investigated: the simultaneous detection of all the discrete objects in the data set, and the iterative detection of objects. In both cases, the parameter space characterizing the object(s) is explored using Markov-chain Monte Carlo sampling. For the iterative detection of objects, another approach is to locate the global maximum of the posterior at each iteration using a simulated annealing downhill simplex algorithm. The techniques are applied to a two-dimensional toy problem consisting of Gaussian objects embedded in uncorrelated pixel noise. A cosmological illustration of the iterative approach is also presented, in which the thermal and kinetic Sunyaev–Zel'dovich effects from clusters of galaxies are detected in microwave maps dominated by emission from primordial cosmic microwave background anisotropies.