photutils.segmentation.detect_threshold(data, nsigma, *, background=None, error=None, mask=None, sigma_clip=SigmaClip(sigma=3.0, sigma_lower=3.0, sigma_upper=3.0, maxiters=10, cenfunc='median', stdfunc='std', grow=False))[source]

Calculate a pixel-wise threshold image that can be used to detect sources.

This is a simple convenience function that uses sigma-clipped statistics to compute a scalar background and noise estimate. In general, one should perform more sophisticated estimates, e.g., using Background2D.

data2D ndarray

The 2D array of the image.


The number of standard deviations per pixel above the background for which to consider a pixel as possibly being part of a source.

backgroundfloat or 2D ndarray, optional

The background value(s) of the input data. background may either be a scalar value or a 2D array with the same shape as the input data. If the input data has been background-subtracted, then set background to 0.0 (this should be typical). If None, then a scalar background value will be estimated as the sigma-clipped image mean.

errorfloat or 2D ndarray, optional

The Gaussian 1-sigma standard deviation of the background noise in data. error should include all sources of “background” error, but exclude the Poisson error of the sources. If error is a 2D image, then it should represent the 1-sigma background error in each pixel of data. If None, then a scalar background rms value will be estimated as the sigma-clipped image standard deviation.

mask2D bool ndarray, optional

A boolean mask with the same shape as data, where a True value indicates the corresponding element of data is masked. Masked pixels are ignored when computing the image background statistics.

sigma_clipastropy.stats.SigmaClip instance, optional

A SigmaClip object that defines the sigma clipping parameters.

threshold2D ndarray

A 2D image with the same shape as data containing the pixel-wise threshold values.


The mask and sigma_clip inputs are used only if it is necessary to estimate background or error using sigma-clipped background statistics. If background and error are both input, then mask and sigma_clip are ignored.