Ejemplo n.º 1
0
        double ComputeWidth(ImageDetection Input)
        {
            double X0Angle = Input.FetchProperty <ObjectSize>().PixelEllipse.SemiaxisMajorAngle;
            /* Rotation matrix: { { Cos(-X0Angle), -Sin(-X0Angle) }, { Sin(-X0Angle), Cos(-X0Angle) } } */
            double YSsum = 0, Ysum = 0;

            if (Input.TryFetchProperty(out ObjectPoints op))
            {
                var pixelPoints = op.PixelPoints;
                foreach (PixelPoint pp in pixelPoints)
                {
                    double nY = pp.Y * Cos(X0Angle) - pp.X * Sin(X0Angle);
                    YSsum += nY * nY;
                    Ysum  += nY;
                }
                YSsum /= pixelPoints.Length;
                Ysum  /= pixelPoints.Length;
                YSsum -= Ysum * Ysum;

                return(2 * Sqrt(YSsum));
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Checks whether a pair of detections makes reasonable sense to become a candidate object.</summary>
        bool VerifyPair(ImageDetection a, ImageDetection b)
        {
            if (a.TryFetchProperty(out PairingProperties ppa) && b.TryFetchProperty(out PairingProperties ppb))
            {
                if (ppa.StarPolluted | ppb.StarPolluted)
                {
                    return(false);
                }
            }

            double ErrRad = MaxLinErrorArcSec * Math.PI / 180 / 3600;

            double MsizeLD = (a.FetchProperty <ObjectSize>().PixelEllipse.SemiaxisMajor + b.FetchProperty <ObjectSize>().PixelEllipse.SemiaxisMajor) * 2;

            MsizeLD *= a.ParentImage.Transform.GetEstimatedWCSChainDerivative();
            double Mdistance    = (a.Barycenter.EP ^ b.Barycenter.EP);
            double DeltaABTimeS = (b.Time.Time - a.Time.Time).TotalSeconds;
            double TExpTime     = a.Time.Exposure.TotalSeconds + b.Time.Exposure.TotalSeconds;

            /* If the distance is too large for light sources too small, no need to check further */
            if ((MsizeLD + ErrRad) * DeltaABTimeS < Mdistance * TExpTime)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public void TryPairDot(ImageDetection a, ImageDetection b)
        {
            if (a.FetchProperty <PairingProperties>().IsPaired || b.FetchProperty <PairingProperties>().IsPaired)
            {
                return;
            }
            TimeSpan DeltaTime             = b.Time.Time - a.Time.Time;
            var      Line                  = b.Barycenter.EP - a.Barycenter.EP;
            double   PairEstimatedDistance = ~Line;

            if (PairEstimatedDistance > MaxVDD * DeltaTime.TotalMinutes)
            {
                return;
            }
            if (PairEstimatedDistance < MinVDD * DeltaTime.TotalMinutes)
            {
                return;
            }
            double PairEstimatedDistanceError = 2 * (a.FetchProperty <ObjectSize>().PixelEllipse.SemiaxisMajor + b.FetchProperty <ObjectSize>().PixelEllipse.SemiaxisMajor);

            PairEstimatedDistanceError *= a.ParentImage.Transform.GetEstimatedWCSChainDerivative();
            double PairEstimatedVelocity                 = PairEstimatedDistance / DeltaTime.TotalSeconds;
            double PairEstimatedVelocityError            = PairEstimatedDistanceError / DeltaTime.TotalSeconds;
            List <List <ImageDetection> > DetectedInPool = new List <List <ImageDetection> >();
            List <ImageDetection[]>       DIPAr          = new List <ImageDetection[]>();

            foreach (DateTime dt in ObsTimes)
            {
                TimeSpan        tsp            = dt - b.Time.Time;
                double          EstDistance    = PairEstimatedVelocity * tsp.TotalSeconds;
                double          EstDistError   = Math.Abs(PairEstimatedVelocityError * tsp.TotalSeconds) + PairEstimatedDistanceError;
                EquatorialPoint EstimatedPoint = Line + EstDistance;
                var             DetectionsList = DetectionPool.Query(EstimatedPoint.RA, EstimatedPoint.Dec, EstDistError);
                DetectionsList.RemoveAll((x) => ((x.Barycenter.EP ^ EstimatedPoint) > EstDistError) || (x.Time.Time != dt) || !x.FetchProperty <PairingProperties>().IsDotDetection);
                //DetectedInPool.Add(DetectionsList);
                DIPAr.Add(DetectionsList.ToArray());
            }
            int i, c = 0;

            for (i = 0; i < DIPAr.Count; i++)
            {
                if (DIPAr[i].Length != 0)
                {
                    c++;
                }
            }
            if (c >= 3)
            {
                CandidatePairings.Add(DIPAr.ToArray());
                foreach (ImageDetection[] mdl in DIPAr)
                {
                    foreach (ImageDetection m in mdl)
                    {
                        m.FetchProperty <PairingProperties>().IsPaired = true;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public bool Filter(ImageDetection Input)
 {
     if (Input.TryFetchProperty(out ObjectPoints op))
     {
         return(op.PixelPoints.Length > MinPix || Input.FetchOrCreate <PairingProperties>().IsDotDetection);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 5
0
        /// <summary>Filters tracklets dependent on a <paramref name="Detection"/> from the list.</summary>
        private void Filter(ImageDetection Detection)
        {
            for (int i = 0; i < CurrentTracklets.Count; i++)
            {
                if (CurrentTracklets[i].Detections.Contains(Detection) && CurrentTracklets[i].Detections.Length == 3)
                {
                    CurrentTracklets.RemoveAt(i); i--;
                }
            }

            RefreshTrackletList();
        }
Ejemplo n.º 6
0
        /// <summary>Attempts to find a tracklet given 2 image detections (from separate images).</summary>
        void AnalyzePair(ImageDetection a, ImageDetection b)
        {
            /* Figure out line vector */
            double SepSec = (b.Time.Time - a.Time.Time).TotalSeconds;

            LinearRegression.LinearRegressionParameters RAT = LinearRegression.ComputeLinearRegression(new double[] { 0, SepSec },
                                                                                                       new double[] { a.Barycenter.EP.RA, b.Barycenter.EP.RA });
            LinearRegression.LinearRegressionParameters DecT = LinearRegression.ComputeLinearRegression(new double[] { 0, SepSec },
                                                                                                        new double[] { a.Barycenter.EP.Dec, b.Barycenter.EP.Dec });

            /* Search for objects */
            List <ImageDetection[]> Dects = new List <ImageDetection[]>();

            foreach (DateTime dt in ObsTimes)
            {
                /* Compute estimated position */
                TimeSpan        tsp        = dt - a.Time.Time;
                double          tspSeconds = tsp.TotalSeconds;
                EquatorialPoint eqp        = new EquatorialPoint()
                {
                    RA = RAT.Intercept + RAT.Slope * tspSeconds, Dec = DecT.Intercept + DecT.Slope * tspSeconds
                };
                /* Limit is given by a triangle with the maximum residuals */
                List <ImageDetection> ImDL = FindSourcesAround(a, b, dt, eqp, SearchExtraSmall);
                if (ImDL.Count == 0)
                {
                    ImDL = FindSourcesAround(a, b, dt, eqp, SearchExtraBig);
                }
                Dects.Add(ImDL.ToArray());
            }

            /* If it can be found on at least 3 images, consider it a detection */
            int i, c = 0;

            for (i = 0; i < Dects.Count; i++)
            {
                if (Dects[i].Length != 0)
                {
                    c++;
                }
            }
            if (c >= 3)
            {
                CandidatePairings.Add(Dects.ToArray());
                foreach (ImageDetection[] mdl in Dects)
                {
                    foreach (ImageDetection m in mdl)
                    {
                        m.FetchOrCreate <PairingProperties>().IsPaired = true;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void ArDel_ImageDetected(object sender, ImageDetection e)
        {
            Vibration.Vibrate();

            var v = new SCNVector3(
                e.Anchor.Transform.Column3.X,
                e.Anchor.Transform.Column3.Y,
                e.Anchor.Transform.Column3.Z);

            PlaceCube(v);

            scnView.Session.RemoveAnchor(e.Anchor);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Finds <see cref="ImageDetection"/>s around the estimated position from other detections.
        /// </summary>
        /// <param name="a">First reference detection.</param>
        /// <param name="b">Second reference detection.</param>
        /// <param name="dt">Time at which to find the new detection.</param>
        /// <param name="eqp">Estimated location of the new detection.</param>
        /// <param name="radius">Search radius around the estimated location.</param>
        /// <returns>A list of <see cref="ImageDetection"/> that match the given conditions.</returns>
        private List <ImageDetection> FindSourcesAround(ImageDetection a, ImageDetection b, DateTime dt, EquatorialPoint eqp, double radius)
        {
            double   SepSec     = (b.Time.Time - a.Time.Time).TotalSeconds;
            TimeSpan tsp        = dt - a.Time.Time;
            double   tspSeconds = tsp.TotalSeconds;

            double RadiusArcSec = tspSeconds * MaxLinErrorArcSec / SepSec + radius;
            double RadiusRad    = RadiusArcSec * Math.PI / 180 / 3600;

            var ImDL = DetectionPool.Query(eqp.RA, eqp.Dec, RadiusRad);

            ImDL.RemoveAll((x) => ((x.Barycenter.EP ^ eqp) > RadiusRad) || Math.Abs((x.Time.Time - dt).TotalSeconds) > .1 || !Line3Way(a, b, x));
            return(ImDL);
        }
Ejemplo n.º 9
0
            public bool Filter(ImageDetection Input)
            {
                double Th = ImgMean + ImgSigma * SigmaTop;

                if (Input.TryFetchProperty(out ObjectPoints op))
                {
                    double[] pv = new double[op.PixelValues.Length];
                    Buffer.BlockCopy(op.PixelValues, 0, pv, 0, pv.Length * sizeof(double));
                    Array.Sort(pv);
                    if (pv[pv.Length / 10] > Th)
                    {
                        return(false);
                    }
                }
                return(true);
            }
Ejemplo n.º 10
0
        /// <summary>Checks whether 3 points are collinear.</summary>
        bool Line3Way(ImageDetection a, ImageDetection b, ImageDetection c)
        {
            double BSec = (b.Time.Time - a.Time.Time).TotalSeconds;
            double CSec = (c.Time.Time - a.Time.Time).TotalSeconds;
            double RAT  = LineFit.ComputeResidualSqSum(new double[] { 0, BSec, CSec },
                                                       new double[] { a.Barycenter.EP.RA, b.Barycenter.EP.RA, c.Barycenter.EP.RA });
            double DecT = LineFit.ComputeResidualSqSum(new double[] { 0, BSec, CSec },
                                                       new double[] { a.Barycenter.EP.Dec, b.Barycenter.EP.Dec, c.Barycenter.EP.Dec });

            double ErrRad = MaxLinErrorArcSec * Math.PI / 180 / 3600;

            if (RAT + DecT > ErrRad * ErrRad)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 11
0
        public bool PairPossible(ImageDetection a, ImageDetection b)
        {
            PairingProperties App = a.FetchOrCreate <PairingProperties>(), Bpp = b.FetchOrCreate <PairingProperties>();

            if (App.IsPaired || Bpp.IsPaired)
            {
                return(false);
            }
            if (App.StarPolluted || Bpp.StarPolluted)
            {
                return(false);
            }
            if (a.Time.Time == b.Time.Time)
            {
                return(false);
            }
            TimeSpan DeltaTime = a.Time.Time - b.Time.Time;
            //if ((a.LargestDistance + b.LargestDistance) * Math.Abs(DeltaTime.TotalSeconds) < (a.Barycenter.EP ^ b.Barycenter.EP) * (a.Time.Exposure.TotalSeconds + b.Time.Exposure.TotalSeconds) / 2) return false;

            SourceEllipse aPel = a.FetchProperty <ObjectSize>().PixelEllipse, bPel = b.FetchProperty <ObjectSize>().PixelEllipse;

            if (aPel.SemiaxisMajor > LongTrailHighThreshold * LongTrailHighThreshold)
            {
                if (bPel.SemiaxisMajor < LongTrailLowThreshold * LongTrailLowThreshold)
                {
                    return(false);
                }
            }
            double DeltaAngle = aPel.SemiaxisMajorAngle - bPel.SemiaxisMajorAngle;
            double Length     = aPel.SemiaxisMajor + bPel.SemiaxisMajor;

            if (DeltaAngle * DeltaAngle * Math.Sqrt(Length) > AngleDistanceDifferenceThreshold)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Filters detections matching a condition.
        /// </summary>
        /// <param name="Detection">Model detection.</param>
        /// <param name="Filter">Filtering predicate.</param>
        /// <param name="Parameter">Predicate parameter.</param>
        private void FilterByDetection(ImageDetection Detection, DetectionFilteringCondition Filter, double Parameter)
        {
            for (int i = 0; i < CurrentTracklets.Count; i++)
            {
                if (CurrentTracklets[i].Detections.Any((x) => Filter(Detection, x, Parameter)))
                {
                    if (CurrentTracklets[i].Detections.Length == 3)
                    {
                        CurrentTracklets.RemoveAt(i); i--;
                    }
                    else
                    {
                        var r = CurrentTracklets[i].Detections.Where((x) => !Filter(Detection, x, Parameter)).ToArray();
                        if (r.Length < 3)
                        {
                            CurrentTracklets.RemoveAt(i);
                        }
                    }
                }
            }

            RefreshTrackletList();
        }
Ejemplo n.º 13
0
 /// <summary>Filters all detections within a <paramref name="RadRadius"/> radius from the <paramref name="Detection"/>.</summary>
 private static bool ConditionRadius(ImageDetection Detection, ImageDetection x, double RadRadius) => (x.Barycenter.EP ^ Detection.Barycenter.EP) < RadRadius;
Ejemplo n.º 14
0
        static ImageDetection Transform(ObsEntry Entry, FitsImage AssociatedImage)
        {
            EquatorialPoint eqp = new EquatorialPoint()
            {
                RA = Entry.RA / 180 * Math.PI, Dec = Entry.Dec / 180 * Math.PI
            };
            PixelPoint pp = new PixelPoint()
            {
                X = Entry.X, Y = Entry.Y
            };
            Position       p   = new Position(eqp, pp);
            ImageDetection det = new ImageDetection(p, AssociatedImage.GetProperty <ObservationTime>(), AssociatedImage);

            bool       Ellipse = false;
            ObjectSize sz      = new ObjectSize();

            if (Entry.A.HasValue && Entry.B.HasValue)
            {
                sz.PixelEllipse = new SourceEllipse()
                {
                    SemiaxisMajor = Entry.A.Value, SemiaxisMinor = Entry.B.Value
                };
                Ellipse = true;
            }
            else if (Entry.FWHM.HasValue && Entry.Ellipticity.HasValue)
            {
                sz.PixelEllipse = new SourceEllipse()
                {
                    SemiaxisMajor = Entry.FWHM.Value / Math.Sqrt(1 - Entry.Ellipticity.Value),
                    SemiaxisMinor = Entry.FWHM.Value * Math.Sqrt(1 - Entry.Ellipticity.Value),
                };
                Ellipse = true;
            }
            if (Ellipse)
            {
                if (Entry.EllipseTheta.HasValue)
                {
                    sz.PixelEllipse.SemiaxisMajorAngle = Entry.EllipseTheta.Value / 180 * Math.PI;
                }
                det.AppendProperty(sz);
            }

            PairingProperties pprop = new PairingProperties()
            {
                IsDotDetection = Ellipse && (sz.PixelEllipse.SemiaxisMajor < 2 * sz.PixelEllipse.SemiaxisMinor),
                IsPaired       = false,
                PearsonR       = 0,
                StarPolluted   = false,
                Algorithm      = DetectionAlgorithm.SourceExtractor
            };

            det.AppendProperty(pprop);
            if (Entry.Flux.HasValue)
            {
                ObjectPhotometry oph = new ObjectPhotometry()
                {
                    Flux = Entry.Flux.Value, Magnitude = Entry.Mag.Value
                };
                det.AppendProperty(oph);
            }

            return(det);
        }
Ejemplo n.º 15
0
        public bool Filter(ImageDetection Input)
        {
            PixelPoint pp = Input.Barycenter.PP;

            return(!BadAreas.Any((x) => x.IsInside(pp)));
        }
Ejemplo n.º 16
0
 /// <summary>Filters all detection with X coordinates within <paramref name="XDelta"/> from the <paramref name="Detection"/>.</summary>
 private static bool ConditionX(ImageDetection Detection, ImageDetection x, double XDelta) => Math.Abs(x.Barycenter.PP.X - Detection.Barycenter.PP.X) < XDelta;
Ejemplo n.º 17
0
 /// <summary>Filters all detection with Y coordinates within <paramref name="YDelta"/> from the <paramref name="Detection"/>.</summary>
 private static bool ConditionY(ImageDetection Detection, ImageDetection x, double YDelta) => Math.Abs(x.Barycenter.PP.Y - Detection.Barycenter.PP.Y) < YDelta;
Ejemplo n.º 18
0
 /// <inheritdoc/>
 public bool Filter(ImageDetection Input) =>
 !(Input.FetchProperty <ObjectPhotometry>().Flux > BrightnessThreshold * Input.FetchProperty <ObjectPoints>().PixelPoints.Length&&
   Input.FetchProperty <ObjectSize>().PixelEllipse.SemiaxisMinor < ThicknessThreshold);
Ejemplo n.º 19
0
 /// <inheritdoc/>
 public bool Filter(ImageDetection Input)
 {
     double Width = ComputeWidth(Input); return(Width <= MaxLineThickness);
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Attempts to recover a detection on a given image, comparing with the entire set of exposures.
        /// </summary>
        /// <returns><c>true</c>, if detection was recovered, <c>false</c> otherwise.</returns>
        /// <param name="DetPos">Position of the detection to recover.</param>
        /// <param name="Img">Image on which to recover.</param>
        /// <param name="Radius">Maximum radius of the detection.</param>
        /// <param name="InputImages">Input images.</param>
        /// <param name="Recovered">Recovered detection.</param>
        public bool RecoverDetection(Position DetPos, Image Img, double Radius, IEnumerable <Image> InputImages, out ImageDetection Recovered)
        {
            Recovered = null;
            DotDetector.DotDetection dd = Recover(DetPos.PP, Radius, Img);
            if (dd.Pixels.Count < MinPix)
            {
                return(false);
            }
            int NoiseCnt = 0;
            int FixedCnt = 0;

            foreach (Image img in InputImages)
            {
                /* Noise scanner -- same position in pixel coordinates */
                DotDetector.DotDetection detN = Recover(dd.Barycenter, Radius, img);
                PixelPoint npp = img.Transform.GetPixelPoint(Img.Transform.GetEquatorialPoint(dd.Barycenter));
                /* Star scanner -- same position in equatorial coordinates */
                DotDetector.DotDetection detF = Recover(npp, Radius, img);
                if (detN.Pixels.Count > NoisePixelThreshold * dd.Pixels.Count)
                {
                    NoiseCnt++;
                }
                if (detF.Flux > StarFluxThreshold * dd.Flux)
                {
                    EquatorialPoint org = DetPos.EP;
                    EquatorialPoint nw  = img.Transform.GetEquatorialPoint(detF.Barycenter);
                    if ((org ^ nw) < MinMoveArcSec)
                    {
                        FixedCnt++;
                    }
                }
            }
            if (NoiseCnt > CrossMatchRemove)
            {
                return(false);
            }
            if (FixedCnt > CrossMatchRemove)
            {
                return(false);
            }

            Recovered = StandardDetectionFactory.CreateDetection(Img, dd.Pixels, dd.PixelValues);
            return(true);
        }