Deformable template models, in which a shape model and its corresponding appearance model are deformed to optimally fit an object in the image, have proven successful in many medical image segmentation tasks. In some applications, the number of objects in an image is not known a priori. In that case not only the most clearly visible object must be extracted, but the full collection of objects present in the image. We propose a stochastic optimization algorithm that optimizes a distribution of shape particles so that the overall distribution explains as much of the image as possible. Possible spatial interrelationships between objects are modelled and used to steer the evolution of the particle set by generating new shape hypotheses that are consistent with the shapes currently observed. The method is evaluated on rib segmentation in chest X-rays.