private void CalculateAndDisplayBackground(uint[,] backgroundPixels)
        {
            if (backgroundPixels != null)
            {
                int bgWidth  = backgroundPixels.GetLength(0);
                int bgHeight = backgroundPixels.GetLength(1);

                var bgPixels = new List <uint>();

                for (int x = 0; x < bgWidth; x++)
                {
                    for (int y = 0; y < bgHeight; y++)
                    {
                        if (m_PSFFit == null || !m_PSFFit.IsSolved ||
                            ImagePixel.ComputeDistance(m_PSFFit.XCenter, x + bgWidth - m_PSFFit.MatrixSize, m_PSFFit.YCenter, y + bgHeight - m_PSFFit.MatrixSize) > 3 * m_PSFFit.FWHM)
                        {
                            bgPixels.Add(backgroundPixels[x, y]);
                        }
                    }
                }

                bgPixels.Sort();
                double background = 0;
                if (bgPixels.Count > 1)
                {
                    background = m_Bpp < 12
                                                ? bgPixels[bgPixels.Count / 2] // for 8 bit videos Median background works better
                                                : bgPixels.Average(x => x);    // for 12+bit videos average background works better
                }

                double residualsSquareSum = 0;
                foreach (uint bgPixel in bgPixels)
                {
                    residualsSquareSum += (background - bgPixel) * (background - bgPixel);
                }
                double noise = Math.Sqrt(residualsSquareSum / (bgPixels.Count - 1));

                lblBackground.Text = background.ToString("0.0");
                lblNoise.Text      = noise.ToString("0.0");

                if (m_PSFFit != null)
                {
                    double snr = m_PSFFit.GetSNR();
                    lblSNR.Text = snr.ToString("0.0");
                }
                else
                {
                    lblSNR.Text = "N/A";
                }

                if (m_PSFFit != null)
                {
                    lblFitVariance.Text = m_PSFFit.GetVariance().ToString("0.0");
                    lblFWHM.Text        = m_PSFFit.FWHM.ToString("0.0");
                }
                else
                {
                    lblFitVariance.Text = "N/A";
                    lblFWHM.Text        = "N/A";
                }
            }
            else
            {
                lblBackground.Text = "N/A";
                lblNoise.Text      = "N/A";
                lblSNR.Text        = "N/A";
            }
        }