Exemple #1
0
        void SetStar(CaptureView capture, RegionView region)
        {
            var xSize = region.VisibleWidth;
            var ySize = region.VisibleHeight;

            var sub = Photometry.GetSubImage(2,
                                             capture.ImageArray,
                                             capture.YSize,
                                             capture.XSize,
                                             region.VisibleY,
                                             region.VisibleX,
                                             region.VisibleY + ySize,
                                             region.VisibleX + xSize);

            var unclipped = Photometry.KappaSigmaClip(sub[0], 1.0, 3);

            var signal  = new ushort[sub[0].Length - unclipped.Count];
            var signals = 0;

            var background  = new ushort[unclipped.Count];
            var backgrounds = 0;

            for (var i = 0; i < sub[0].Length; i++)
            {
                if (unclipped.Contains(i))
                {
                    background[backgrounds++] = sub[0][i];
                }
                else
                {
                    signal[signals++] = sub[0][i];
                }
            }

            var regionMean      = Photometry.FindMean(sub[0]);
            var backgroundSigma = Photometry.FindStandardDeviation(background);
            var backgroundMean  = Photometry.FindMean(background);

            Focus.Star.SetStats(signals, backgrounds, regionMean, backgroundSigma, backgroundMean);

            var snr = regionMean / backgroundSigma;

            var bg = Focus.UsePhdBackgroundFormula ? regionMean + backgroundSigma * 2.0 : regionMean;

            Photometry.Subtract(sub[0], (ushort)bg);

            if (Focus.UseMedianFilter)
            {
                sub[0] = Photometry.MedianBoxFilter(sub[0], xSize, ySize);
            }

            Focus.Region.Capture = new CaptureView
            {
                XSize      = xSize,
                YSize      = ySize,
                ImageArray = sub[0],
                Image      = new Mat(ySize, xSize, MatType.CV_16UC1, sub[0])
            };

            Focus.RegionChanged();

            if (signals < 5)
            {
                Focus.Star.SetStarNotFound();
            }
            else
            {
                var brightestX = 0;
                var brightestY = 0;
                var br         = 0;

                for (var y = 0; y < ySize; y++)
                {
                    for (var x = 0; x < xSize; x++)
                    {
                        var brightest = brightestY * xSize + brightestX;

                        if (sub[0][brightest] < sub[0][y * xSize + x])
                        {
                            brightestX = x;
                            brightestY = y;
                            br         = sub[0][brightest];
                        }
                    }
                }

                var center = Photometry.FindCenterOfMass(sub[0], xSize, ySize);

                ushort peak = 0;

                for (var i = 0; i < sub[0].Length; i++)
                {
                    if (sub[0][i] > peak)
                    {
                        peak = sub[0][i];
                    }
                }

                var weightedCenterX = (center.X / (double)xSize) * 100.0;
                var weightedCenterY = (center.Y / (double)ySize) * 100.0;
                var brightestPixelX = (brightestX / (double)xSize) * 100.0;
                var brightestPixelY = (brightestY / (double)ySize) * 100.0;

                Focus.Star.SetMeasurements(
                    snr,
                    peak,
                    weightedCenterX,
                    weightedCenterY,
                    brightestPixelX,
                    brightestPixelY);

                var samples = new ushort[40];
                var max     = 0.0;

                for (var x = 0; x < 40; x++)
                {
                    samples[x] = sub[0][(int)center.Y * 40 + x];
                    max        = samples[x] > max ? samples[x] : max;
                }

                Focus.SetProfileSamples(samples);
            }
        }