It works in two stages:
Floating-point Not-a-Number (NaNs) and infinities are rejected as bad data. If more than 10−5 of the pixels are exactly zero, it is assumed that zero also marks bad data and these are rejected.
A first guess is made by finding the rms and mean of the good data. These are used to choose bins for a histogram, covering ± 2σ around the mean, with enough points in each bin to make random fluctuations unlikely to change the mode. If the modal bin falls in the outer 20% of the histogram, the histogram is re-made with finer bins, centred on the mode, and this is iterated if necessary.
The final mode is found by a quadratic fit to the five bins centred on the histogram peak. This is our estimate of the true zero level. The noise estimate is the one-sided rms below the mode. You can plot the histogram and quadratic fit if you run auto-scale from the Load FITS or Adjust scaling dialogs. For large HEALPix images it is quicker to run auto-scale when the data is first loaded, because then there is no need to process the large number of "off-sky" pixels which pad out the 2-D projected image.
NB: This algorithm will fail if the histogram is montonically decreasing, e.g. in MEM images.
The image is classified as positive, negative or neutral according to whether (max − mode) / (mode − min) is > 5, < 0.2, or in between. If neutral, the scale is set symmetrically around the mode; if positive it runs from mode − 3σ to a large positive value, and vice-versa for negative images. The scale is truncated at the actual minimum and maximum if this prescription exceeds them. The total range is chosen according to the colour table and transfer function in use. For linear scaling it varies from 50σ for the very contrasty "Cyclic" scale to 18σ for the "Red-black-blue" scale. The ranges are squared for the Sqrt function, and the whole data range is used for Asinh. Histogram equalization uses a nominal range of 400σ.