Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new ImageDetection from a given image, set of points and values. It also populates it with <see cref="ObjectPhotometry"/>, <see cref="ObjectPoints"/>,
        /// and <see cref="ObjectSize"/> properties.
        /// </summary>
        /// <param name="Image">Image on which the object was detected.</param>
        /// <param name="Points">The set of points on the image where it has been detected.</param>
        /// <param name="Values">The set of pixel intensitities.</param>
        /// <returns>A new instance of ImageDetection with the specified extension properties.</returns>
        public static ImageDetection CreateDetection(Image Image, IEnumerable <PixelPoint> Points, IEnumerable <double> Values)
        {
            IWCSProjection Transform = Image.Transform;

            PixelPoint[]      PixPoints        = Points.ToArray();
            double[]          PixValues        = Values.ToArray();
            EquatorialPoint[] EquatorialPoints = Transform.GetEquatorialPoints(PixPoints);

            double Xmean = 0, Ymean = 0;
            double XXP = 0, XYP = 0, YYP = 0;
            double XXB = 0, XYB = 0, YYB = 0;
            double Flux = 0;
            double XBmean = 0, YBmean = 0;

            for (int i = 0; i < PixPoints.Length; i++)
            {
                PixelPoint pt  = PixPoints[i];
                double     Val = PixValues[i];
                Xmean  += pt.X; Ymean += pt.Y;
                XBmean += Val * pt.X; YBmean += Val * pt.Y;
                XXB    += pt.X * pt.X * Val; XYB += pt.X * pt.Y * Val; YYB += pt.Y * pt.Y * Val;
                XXP    += pt.X * pt.X; XYP += pt.X * pt.Y; YYP += pt.Y * pt.Y;
                Flux   += Val;
            }
            Xmean  /= PixPoints.Length; Ymean /= PixPoints.Length;
            XBmean /= Flux; YBmean /= Flux; XXB /= Flux; XYB /= Flux; YYB /= Flux;
            XXP    /= PixPoints.Length; XYP /= PixPoints.Length; YYP /= PixPoints.Length;
            XXB    -= XBmean * XBmean; XYB -= XBmean * YBmean; YYB -= YBmean * YBmean;
            XXP    -= Xmean * Xmean; XYP -= Xmean * Ymean;     YYP -= Ymean * Ymean;

            PixelPoint BarycenterPP = new PixelPoint()
            {
                X = XBmean, Y = YBmean
            };
            EquatorialPoint BarycenterEP = Transform.GetEquatorialPoint(BarycenterPP);
            Position        Pos          = new Position(BarycenterEP, BarycenterPP);

            SourceEllipse BarycentricEllipse = new SourceEllipse(XXB, XYB, YYB);
            SourceEllipse PixelEllipse       = new SourceEllipse(XXP, XYP, YYP);

            ObjectSize Shape = new ObjectSize()
            {
                BarycentricEllipse = BarycentricEllipse, PixelEllipse = PixelEllipse
            };

            ImageDetection Detection = new ImageDetection(Pos, Image.GetProperty <ObservationTime>(), Image);

            Detection.AppendProperty(Shape);
            Detection.AppendProperty(new ObjectPhotometry()
            {
                Flux = Flux
            });
            Detection.AppendProperty(new ObjectPoints()
            {
                PixelPoints = PixPoints, PixelValues = PixValues, EquatorialPoints = EquatorialPoints
            });
            return(Detection);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new ImageDetection by merging the blobs of other detections. Requires the input ImageDetections to have <see cref="ObjectPoints"/> property.
        /// </summary>
        /// <param name="Detections">The list of input detections to merge.</param>
        /// <returns>A new instance of ImageDetection.</returns>
        public static ImageDetection MergeStandardDetections(ImageDetection[] Detections)
        {
            List <PixelPoint> Pixels   = new List <PixelPoint>();
            List <double>     Values   = new List <double>();
            PairingProperties KeptProp = null;

            foreach (ImageDetection imd in Detections)
            {
                if (imd.TryFetchProperty(out ObjectPoints ojp))
                {
                    Pixels.AddRange(ojp.PixelPoints);
                    Values.AddRange(ojp.PixelValues);
                    imd.TryFetchProperty(out PairingProperties Kprop);
                    if (KeptProp == null)
                    {
                        KeptProp = Kprop;
                    }
                    else
                    {
                        KeptProp.Algorithm |= Kprop.Algorithm;
                    }
                }
            }

            if (Pixels.Count == 0)
            {
                if (Detections.Length != 1)
                {
                    if (KeptProp == null)
                    {
                        KeptProp = new PairingProperties();
                    }
                    KeptProp.MultiNoPoints = true;
                }
                return(Detections[0]);
            }
            ImageDetection Result = StandardDetectionFactory.CreateDetection(Detections[0].ParentImage, Pixels, Values);

            if (KeptProp != null)
            {
                Result.SetResetProperty(KeptProp);
            }
            return(Result);
        }