示例#1
0
        public StarFinder(Bitmap image)
        {
            BoundingRects = new BoundingRectList();
            var id  = MakeGrayscale3(image);
            var arr = GetIntArrayFromImage(id);

            ImageData = arr;
        }
示例#2
0
        //  STAR FINDER ALGORITHM FUNCTIONS
        public BoundingRectList FindAllStars(int[,] arr)
        {
            int threshold           = Threshold;
            int minSize             = MinSize;
            BoundingRectList result = new BoundingRectList();
            int xmax = arr.GetUpperBound(0);
            int ymax = arr.GetUpperBound(1);

            //Top-level loop
            for (int y = 0; y < ymax + 1; y++)
            {
                for (int x = 0; x < xmax + 1; x++)
                {
                    Console.WriteLine("Evaluating " + x + ":" + y + "  Value: " + arr[x, y]);
                    if (result.ContainsPoint(x, y)) //Is point already in a blob
                    {
                        Console.WriteLine("--Already in BR");
                        continue;               //point is already in a bounding rect
                    }
                    if (arr[x, y] >= Threshold) // Edge found
                    {
                        Console.WriteLine("--Edge found");
                        Tuple <int, int, int> bar = GetBottomBoundingBar(arr, x, y, Threshold);
                        int xMin = bar.Item1;
                        int xMax = bar.Item2;
                        int yMax = bar.Item3;
                        int yMin = y; //TODO: *** IS THIS CORRECT ??

                        int[,] subImage = GetSubArray(arr, xMin, yMin, xMax, yMax);
                        BoundingRect rect = new BoundingRect(subImage, xMin, yMin, xMax, yMax);
                        Console.WriteLine("--->BR found at [" + xMin + "," + yMin + "],[" + xmax + "," + ymax + "]");

                        if (((xMax - xMin) >= minSize) && ((yMax - yMin) >= minSize))
                        {
                            //if (!result.BrIntersectsAnotherBr(rect))
                            //{
                            result.BrList.Add(rect);
                            Console.WriteLine(" ---->  BR added");
                            //}
                            //else
                            //{
                            //    Console.WriteLine("*** Rejected because it intersects another br");
                            //}
                        }
                        else
                        {
                            Console.WriteLine("*** Rejected due to small size");
                        }
                    }
                    else  //Edge not detected
                    {
                        Console.WriteLine("--No Edge");
                    }
                }
            }
            BoundingRects = result;
            return(result);
        }
示例#3
0
        private void cmdIterate_Click(object sender, EventArgs e)
        {
            int minSize = Convert.ToInt16(txtMinSize.Text);

            Threshold = Convert.ToInt16(txtEdgeThreshold.Text);
            Bitmap img         = new Bitmap(txtSourceFile.Text);
            int    upperXBound = -1;
            int    lowerXBound = -1;
            int    upperYBound = -1;
            int    lowerYBound = -1;
            int    xImage      = img.Height;
            int    yImage      = img.Width;

            int[,] arr = new int[xImage, yImage];
            arr        = GetIntArrayFromImage(img);
            //ImageArray = arr;   //Used for writing out the subframes.
            sf.Threshold = Convert.ToInt16(txtEdgeThreshold.Text);
            sf.MinSize   = Convert.ToInt16(txtMinSize.Text);


            Stopwatch sw = new Stopwatch();

            sw.Start();
            BoundingRectList result = sf.FindAllStars(arr);

            sw.Stop();
            if (rbAbsoluteBrightness.Checked)
            {
                sf.BoundingRects.SortOrder = BoundingRectList.SortOrderEnum.AbsoluteBrightness;
            }
            if (rbCentroid.Checked)
            {
                sf.BoundingRects.SortOrder = BoundingRectList.SortOrderEnum.CentroidLocation;
            }
            if (rbRelativeBrightness.Checked)
            {
                sf.BoundingRects.SortOrder = BoundingRectList.SortOrderEnum.RelativeBrightness;
            }
            if (rbSize.Checked)
            {
                sf.BoundingRects.SortOrder = BoundingRectList.SortOrderEnum.Volume;
            }
            if (rbUpperLefftCoord.Checked)
            {
                sf.BoundingRects.SortOrder = BoundingRectList.SortOrderEnum.UpperLeft;
            }
            sf.BoundingRects.SortList();
            lblElapsedTime.Text = "Elapsed Time: " + sw.ElapsedMilliseconds;

            DumpBoundingRectList(sf.BoundingRects);
        }
示例#4
0
        private void DumpBoundingRectList(BoundingRectList brList)
        {
            int count = 0;

            foreach (var item in brList.BrList)
            {
                string message = string.Format("{0}  BR at [({1},{2}),({3},{4})] Volume={5}", count, item.OriginalUpperLeftX, item.OriginalUpperLeftY, item.OriginalBottomRightX, item.OriginalBottomRightY, item.Volume);
                message += string.Format(" Centroid = ({0:G2},{1:G2})", item.CentroidX, item.CentroidY);
                message += string.Format("  Abs Brightness = {0:G5}  Rel Brightness = {1:G5}", item.AbsoluteBrightness, item.RelativeBrightness);
                message += Environment.NewLine;
                //string msg = count + "  ";
                //msg += "Found BR at [" + item.UpperLeftX + "," + item.UpperLeftY + "],[" + item.BottomRightX + "," + item.BottomRightY + "]";
                //txtOutput.Text += msg + " Volume:" + item.Volume + "  Centroid: [" + item.CentroidX + "," + item.CentroidY + "]";
                txtOutput.Text += message;
                count++;
            }
        }
示例#5
0
 //  ctors
 public StarFinder(int[,] imageData)
 {
     BoundingRects = new BoundingRectList();
     ImageData     = imageData;
 }