Confocal microscopy provides a powerful tool for biologists to investigate gene expression in a 3D manner. However, due to the inherent properties of confocal images, it is difficult to accurately segregate foreground signals from the background using direct thresholding. Therefore, there is a need for a segmentation algorithm that can be used with fluorescent confocal images of gene expression. We present an automatic segmentation algorithm for thresholding confocal images of gene expression in biological samples. The algorithm, called density-based segmentation (DBS), is modified from a noise-tolerant data clustering algorithm (DENCLUE). We demonstrate the utility of this algorithm in different synthetic images as well as in confocal images of zebrafish embryos, with comparison to Otsu's algorithm, which employs direct thresholding. The results of segmentation in synthetic images show that the DBS algorithm is noise-tolerant and is able to distinguish two objects located close to each other. In addition, the results of segmentation in confocal images show that the DBS algorithm can threshold objects while preserving morphological details of internal structures. Therefore, the proposed DBS algorithm is a better segmentation technique than direct thresholding in the segmentation of fluorescent confocal images.