Ejemplo n.º 1
0
        internal static List <PotentialStarStruct> GetPeakPixelsInArea(
            uint[,] data, out uint[,] lpdData, int bpp, uint maxSignalValue, uint aboveNoiseLevelRequired,
            double minDistanceInPixels, bool useLPDFilter, Rectangle excludeArea)
        {
            if (useLPDFilter)
            {
                lpdData = ImageFilters.LowPassDifferenceFilter(data, bpp, false);
            }
            else
            {
                lpdData = data;
            }

            int nWidth  = lpdData.GetLength(0);
            int nHeight = lpdData.GetLength(1);

            List <PotentialStarStruct> potentialStars = new List <PotentialStarStruct>();

            ExaminePeakPixelCandidate examinePixelCallback =
                delegate(int x, int y, uint z)
            {
                bool tooClose = false;

                // Local maximum, test for a star
                foreach (PotentialStarStruct prevStar in potentialStars)
                {
                    double dist =
                        Math.Sqrt((prevStar.X - x) * (prevStar.X - x) +
                                  (prevStar.Y - y) * (prevStar.Y - y));
                    if (dist <= minDistanceInPixels)
                    {
                        tooClose = true;
                        if (prevStar.Z < z)
                        {
                            prevStar.Z = z;
                            prevStar.X = x;
                            prevStar.Y = y;
                        }

                        break;
                    }
                }

                if (!tooClose)
                {
                    potentialStars.Add(new PotentialStarStruct()
                    {
                        X = x, Y = y, Z = z
                    });
                }

                // An early return if too many peak pixels have been found
                return(potentialStars.Count <=
                       TangraConfig.Settings.Special.
                       StarFinderMaxNumberOfPotentialStars);
            };

            if (useLPDFilter)
            {
                CheckAllPixels(lpdData, nWidth, nHeight, aboveNoiseLevelRequired, excludeArea, examinePixelCallback);
            }
            else
            {
                CheckPixelsFromBrightToFaint(lpdData, nWidth, nHeight, bpp, maxSignalValue, aboveNoiseLevelRequired, excludeArea, examinePixelCallback);
            }

            return(potentialStars);
        }
Ejemplo n.º 2
0
        private static void CheckPixelsFromBrightToFaint(
            uint[,] data, int nWidth, int nHeight, int bpp, uint maxSignalValue, uint aboveNoiseLevelRequired, Rectangle excludeArea, ExaminePeakPixelCandidate callback)
        {
            bool excludeAreaDefined = Rectangle.Empty != excludeArea;

            int includsionCheckStep = 10;

            if (bpp == 12)
            {
                includsionCheckStep = 50;
            }
            else if (bpp == 14)
            {
                includsionCheckStep = 60;
            }
            else if (bpp == 16)
            {
                includsionCheckStep = 100;
            }

            int maxPixelValue = 255;

            if (bpp > 8)
            {
                maxPixelValue = (int)maxSignalValue;
            }

            int currInclusionLimit = maxPixelValue - includsionCheckStep + 1;

            while (currInclusionLimit > aboveNoiseLevelRequired)
            {
                for (int i = 1; i < nWidth - 1; i++)
                {
                    for (int j = 1; j < nHeight - 1; j++)
                    {
                        if (excludeAreaDefined && excludeArea.Contains(i, j))
                        {
                            continue;
                        }

                        uint testedPixel = data[i, j];

                        if (testedPixel > currInclusionLimit &&
                            testedPixel <= currInclusionLimit + includsionCheckStep &&
                            testedPixel >= data[i - 1, j] &&
                            testedPixel >= data[i - 1, j - 1] &&
                            testedPixel >= data[i, j - 1] &&
                            testedPixel >= data[i + 1, j - 1] &&
                            testedPixel >= data[i + 1, j] &&
                            testedPixel >= data[i + 1, j + 1] &&
                            testedPixel >= data[i, j + 1] &&
                            testedPixel >= data[i - 1, j + 1])
                        {
                            if (!callback(i, j, testedPixel))
                            {
                                return;
                            }
                        }
                    }
                }

                currInclusionLimit -= includsionCheckStep;
            }
        }
Ejemplo n.º 3
0
        private static void CheckPixelsFromBrightToFaint(
            uint[,] data, int nWidth, int nHeight, int bpp, uint maxSignalValue, uint aboveNoiseLevelRequired, Rectangle excludeArea, ExaminePeakPixelCandidate callback)
        {
            bool excludeAreaDefined = Rectangle.Empty != excludeArea;

            int includsionCheckStep = 10;
            if (bpp == 12) includsionCheckStep = 50;
            else if (bpp == 14) includsionCheckStep = 60;
            else if (bpp == 16) includsionCheckStep = 100;

            int maxPixelValue = 255;
            if (bpp > 8) maxPixelValue = (int)maxSignalValue;

            int currInclusionLimit = maxPixelValue - includsionCheckStep + 1;

            while (currInclusionLimit > aboveNoiseLevelRequired)
            {
                for (int i = 1; i < nWidth - 1; i++)
                    for (int j = 1; j < nHeight - 1; j++)
                    {
                        if (excludeAreaDefined && excludeArea.Contains(i, j))
                            continue;

                        uint testedPixel = data[i, j];

                        if (testedPixel > currInclusionLimit &&
                            testedPixel <= currInclusionLimit + includsionCheckStep &&
                            testedPixel >= data[i - 1, j] &&
                            testedPixel >= data[i - 1, j - 1] &&
                            testedPixel >= data[i, j - 1] &&
                            testedPixel >= data[i + 1, j - 1] &&
                            testedPixel >= data[i + 1, j] &&
                            testedPixel >= data[i + 1, j + 1] &&
                            testedPixel >= data[i, j + 1] &&
                            testedPixel >= data[i - 1, j + 1])
                        {
                            if (!callback(i, j, testedPixel))
                                return;
                        }
                    }

                currInclusionLimit -= includsionCheckStep;
            }
        }
Ejemplo n.º 4
0
        private static void CheckAllPixels(uint[,] data, int nWidth, int nHeight, uint aboveNoiseLevelRequired, Rectangle excludeArea, ExaminePeakPixelCandidate callback)
        {
            bool excludeAreaDefined = Rectangle.Empty != excludeArea;

            for (int i = 1; i < nWidth - 1; i++)
            {
                for (int j = 1; j < nHeight - 1; j++)
                {
                    if (excludeAreaDefined && excludeArea.Contains(i, j))
                    {
                        continue;
                    }

                    uint testedPixel = data[i, j];

                    if (testedPixel > aboveNoiseLevelRequired &&
                        testedPixel >= data[i - 1, j] &&
                        testedPixel >= data[i - 1, j - 1] &&
                        testedPixel >= data[i, j - 1] &&
                        testedPixel >= data[i + 1, j - 1] &&
                        testedPixel >= data[i + 1, j] &&
                        testedPixel >= data[i + 1, j + 1] &&
                        testedPixel >= data[i, j + 1] &&
                        testedPixel >= data[i - 1, j + 1])
                    {
                        if (!callback(i, j, testedPixel))
                        {
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static void CheckAllPixels(uint[,] data, int nWidth, int nHeight, uint aboveNoiseLevelRequired, Rectangle excludeArea, ExaminePeakPixelCandidate callback)
        {
            bool excludeAreaDefined = Rectangle.Empty != excludeArea;

            for (int i = 1; i < nWidth - 1; i++)
                for (int j = 1; j < nHeight - 1; j++)
                {
                    if (excludeAreaDefined && excludeArea.Contains(i, j))
                        continue;

                    uint testedPixel = data[i, j];

                    if (testedPixel > aboveNoiseLevelRequired &&
                        testedPixel >= data[i - 1, j] &&
                        testedPixel >= data[i - 1, j - 1] &&
                        testedPixel >= data[i, j - 1] &&
                        testedPixel >= data[i + 1, j - 1] &&
                        testedPixel >= data[i + 1, j] &&
                        testedPixel >= data[i + 1, j + 1] &&
                        testedPixel >= data[i, j + 1] &&
                        testedPixel >= data[i - 1, j + 1])
                    {
                        if (!callback(i, j, testedPixel))
                            return;
                    }
                }
        }