photutils.segmentation.deblend_sources(data, segment_img, npixels, kernel=None, labels=None, nlevels=32, contrast=0.001, mode='exponential', connectivity=8, relabel=True)[source]

Deblend overlapping sources labeled in a segmentation image.

Sources are deblended using a combination of multi-thresholding and watershed segmentation. In order to deblend sources, there must be a saddle between them.


The data array.

segment_imgSegmentationImage or array_like (int)

A segmentation image, either as a SegmentationImage object or an ndarray, with the same shape as data where sources are labeled by different positive integer values. A value of zero is reserved for the background.


The number of connected pixels, each greater than threshold, that an object must have to be detected. npixels must be a positive integer.

filterarray-like or Kernel2D, optional

The array of the kernel used to filter the image before thresholding. Filtering the image will smooth the noise and maximize detectability of objects with a shape similar to the kernel.

labelsint or array-like of int, optional

The label numbers to deblend. If None (default), then all labels in the segmentation image will be deblended.

nlevelsint, optional

The number of multi-thresholding levels to use. Each source will be re-thresholded at nlevels levels spaced exponentially or linearly (see the mode keyword) between its minimum and maximum values within the source segment.

contrastfloat, optional

The fraction of the total (blended) source flux that a local peak must have (at any one of the multi-thresholds) to be considered as a separate object. contrast must be between 0 and 1, inclusive. If contrast = 0 then every local peak will be made a separate object (maximum deblending). If contrast = 1 then no deblending will occur. The default is 0.001, which will deblend sources with a 7.5 magnitude difference.

mode{‘exponential’, ‘linear’}, optional

The mode used in defining the spacing between the multi-thresholding levels (see the nlevels keyword). The default is ‘exponential’.

connectivity{8, 4}, optional

The type of pixel connectivity used in determining how pixels are grouped into a detected source. The options are 8 (default) or 4. 8-connected pixels touch along their edges or corners. 4-connected pixels touch along their edges. For reference, SourceExtractor uses 8-connected pixels.


If True (default), then the segmentation image will be relabeled such that the labels are in consecutive order starting from 1.


A segmentation image, with the same shape as data, where sources are marked by different positive integer values. A value of zero is reserved for the background.