Exemple #1
0
        public static List <PSFFit> GetStarsInArea(
            ref uint[,] data, int bpp, uint maxSignalValue, TangraConfig.PreProcessingFilter filter,
            List <PotentialStarStruct> allPotentialStars,
            List <PSFFit> allFoundStars,
            uint aboveNoiseLevelRequired, double minDistanceInPixels,
            bool useLPDFilter, Rectangle excludeArea, FilterPotentialStars filterCallback)
        {
            double minFWHM = TangraConfig.Settings.Special.StarFinderMinFWHM;
            double maxFWHM = TangraConfig.Settings.Special.StarFinderMaxFWHM;

            int STAR_MATRIX_FIT = TangraConfig.Settings.Special.StarFinderFitArea;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            uint[,] lpdData;
            List <PotentialStarStruct> potentialStars = GetPeakPixelsInArea(
                data, out lpdData, bpp, maxSignalValue, aboveNoiseLevelRequired, minDistanceInPixels, useLPDFilter, excludeArea);

            if (filterCallback != null)
            {
                filterCallback(potentialStars);
            }
            sw.Stop();
            Trace.WriteLine(string.Format("GetPeakPixelsInArea: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00")));

            if (potentialStars.Count > 3)
            {
                // Only include the 3 brightest stars. The other ones cannot be stars
                potentialStars.Sort((x, y) => y.Z.CompareTo(x.Z));
                potentialStars = potentialStars.Take(3).ToList();
            }

            // Debugging purposes
            if (allPotentialStars != null)
            {
                allPotentialStars.AddRange(potentialStars);
            }

            uint[,] lpData = data;

            List <PSFFit> foundStars = new List <PSFFit>();

            double MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER = TangraConfig.Settings.Special.StarFinderMinDistanceOfPeakPixelFromCenter;

            sw.Reset();
            sw.Start();

            foreach (PotentialStarStruct starToTest in potentialStars)
            {
                PSFFit fit       = new PSFFit(starToTest.X, starToTest.Y);
                int    fitMatrix = (int)Math.Min(data.GetLength(0), STAR_MATRIX_FIT + 2);

                // Get a matrix with 1 pixel larger each way and set the border pixels to zero
                fit.Fit(lpData, fitMatrix, starToTest.X, starToTest.Y, true);

                if (fit.IsSolved)
                {
                    double distanceFromCenter = ImagePixel.ComputeDistance(fit.X0_Matrix, fitMatrix / 2, fit.Y0_Matrix, fitMatrix / 2);

                    if (fit.Certainty > 0 &&
                        fit.FWHM >= minFWHM &&
                        fit.FWHM <= maxFWHM &&
                        distanceFromCenter < MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER &&
                        fit.IMax > aboveNoiseLevelRequired)
                    {
                        // This object passes all tests to be furhter considered as a star
                        foundStars.Add(fit);
                    }
                }


                if (allFoundStars != null)
                {
                    allFoundStars.Add(fit);
                }
            }

            foundStars.Sort((f1, f2) => f1.IMax.CompareTo(f2.IMax));

            PSFFit[] testStars = foundStars.ToArray();
            for (int i = 0; i < testStars.Length; i++)
            {
                PSFFit fainterStar = testStars[i];
                for (int j = i + 1; j < testStars.Length; j++)
                {
                    PSFFit brighterStar = testStars[j];

                    if (fainterStar.UniqueId == brighterStar.UniqueId)
                    {
                        continue;
                    }

                    // If a the max of a fainter star is inside the fit of a brighter star
                    // then see if it is simply not a point of the other star

                    double dist = Math.Sqrt((fainterStar.XCenter - brighterStar.XCenter) * (fainterStar.XCenter - brighterStar.XCenter) + (fainterStar.YCenter - brighterStar.YCenter) * (fainterStar.YCenter - brighterStar.YCenter));
                    if (dist <= minDistanceInPixels)
                    {
                        if (foundStars.Contains(fainterStar))
                        {
                            foundStars.Remove(fainterStar);
                        }
                    }
                }
            }
            sw.Stop();
            Trace.WriteLine(string.Format("Doing PSFFitting: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00")));

            switch (filter)
            {
            case TangraConfig.PreProcessingFilter.NoFilter:
                break;

            case TangraConfig.PreProcessingFilter.LowPassFilter:
                data = lpData;
                break;

            case TangraConfig.PreProcessingFilter.LowPassDifferenceFilter:
                data = lpdData;
                break;
            }

            return(foundStars);
        }
Exemple #2
0
        public static List<PSFFit> GetStarsInArea(
            ref uint[,] data, int bpp, uint maxSignalValue, TangraConfig.PreProcessingFilter filter,
            List<PotentialStarStruct> allPotentialStars,
            List<PSFFit> allFoundStars,
            uint aboveNoiseLevelRequired, double minDistanceInPixels,
            bool useLPDFilter, Rectangle excludeArea, FilterPotentialStars filterCallback)
        {
            double minFWHM = TangraConfig.Settings.Special.StarFinderMinFWHM;
            double maxFWHM = TangraConfig.Settings.Special.StarFinderMaxFWHM;

            int STAR_MATRIX_FIT = TangraConfig.Settings.Special.StarFinderFitArea;

            Stopwatch sw = new Stopwatch();
            sw.Start();
            uint[,] lpdData;
            List<PotentialStarStruct> potentialStars = GetPeakPixelsInArea(
                data, out lpdData, bpp, maxSignalValue, aboveNoiseLevelRequired, minDistanceInPixels, useLPDFilter, excludeArea);

            if (filterCallback != null) filterCallback(potentialStars);
            sw.Stop();
            Trace.WriteLine(string.Format("GetPeakPixelsInArea: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00")));

            if (potentialStars.Count > 3)
            {
                // Only include the 3 brightest stars. The other ones cannot be stars
                potentialStars.Sort((x, y) => y.Z.CompareTo(x.Z));
                potentialStars = potentialStars.Take(3).ToList();
            }

            // Debugging purposes
            if (allPotentialStars != null)
                allPotentialStars.AddRange(potentialStars);

            uint[,] lpData = data;

            List<PSFFit> foundStars = new List<PSFFit>();

            double MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER = TangraConfig.Settings.Special.StarFinderMinDistanceOfPeakPixelFromCenter;

            sw.Reset();
            sw.Start();

            foreach (PotentialStarStruct starToTest in potentialStars)
            {
                PSFFit fit = new PSFFit(starToTest.X, starToTest.Y);
                int fitMatrix = (int)Math.Min(data.GetLength(0), STAR_MATRIX_FIT + 2);

                // Get a matrix with 1 pixel larger each way and set the border pixels to zero
                fit.Fit(lpData, fitMatrix, starToTest.X, starToTest.Y, true);

                if (fit.IsSolved)
                {
                    double distanceFromCenter = ImagePixel.ComputeDistance(fit.X0_Matrix, fitMatrix / 2, fit.Y0_Matrix, fitMatrix / 2);

                    if (fit.Certainty > 0 &&
                        fit.FWHM >= minFWHM &&
                        fit.FWHM <= maxFWHM &&
                        distanceFromCenter < MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER &&
                        fit.IMax > aboveNoiseLevelRequired)
                    {

                        // This object passes all tests to be furhter considered as a star
                        foundStars.Add(fit);
                    }
                }

                if (allFoundStars != null)
                    allFoundStars.Add(fit);
            }

            foundStars.Sort((f1, f2) => f1.IMax.CompareTo(f2.IMax));

            PSFFit[] testStars = foundStars.ToArray();
            for (int i = 0; i < testStars.Length; i++)
            {
                PSFFit fainterStar = testStars[i];
                for (int j = i + 1; j < testStars.Length; j++)
                {
                    PSFFit brighterStar = testStars[j];

                    if (fainterStar.UniqueId == brighterStar.UniqueId) continue;

                    // If a the max of a fainter star is inside the fit of a brighter star
                    // then see if it is simply not a point of the other star

                    double dist = Math.Sqrt((fainterStar.XCenter - brighterStar.XCenter) * (fainterStar.XCenter - brighterStar.XCenter) + (fainterStar.YCenter - brighterStar.YCenter) * (fainterStar.YCenter - brighterStar.YCenter));
                    if (dist <= minDistanceInPixels)
                    {
                        if (foundStars.Contains(fainterStar)) foundStars.Remove(fainterStar);
                    }
                }
            }
            sw.Stop();
            Trace.WriteLine(string.Format("Doing PSFFitting: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00")));

            switch (filter)
            {
                case TangraConfig.PreProcessingFilter.NoFilter:
                    break;

                case TangraConfig.PreProcessingFilter.LowPassFilter:
                    data = lpData;
                    break;

                case TangraConfig.PreProcessingFilter.LowPassDifferenceFilter:
                    data = lpdData;
                    break;
            }

            return foundStars;
        }