Exemplo 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);
        }
Exemplo n.º 2
0
 protected Image(int ImageNumber, IWCSProjection Transform, HeaderTable Header, uint Width, uint Height)
 {
     this.ImageNumber          = ImageNumber;
     this.Transform            = Transform;
     this.Header               = Header;
     this.Width                = Width;
     this.Height               = Height;
     this.PropertiesDictionary = new Dictionary <Type, ImageProperties>();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Performs a median filter between multiple data sets.
        /// </summary>
        /// <param name="Inputs">Input data.</param>
        /// <param name="Output">Output data.</param>
        /// <param name="InputPositions">Input alignments.</param>
        /// <param name="OutputPosition">Output alignment.</param>
        /// <param name="empty">Dummy argument.</param>
        static void MultiImageMedianFilter(double[][,] Inputs, double[,] Output, SchedCore.ImageSegmentPosition[] InputPositions, SchedCore.ImageSegmentPosition OutputPosition, object empty)
        {
            PixelPoint[] InputAlignments = InputPositions.Select((x) => x.Alignment).ToArray();
            PixelPoint   OutputAlignment = OutputPosition.Alignment;

            IWCSProjection[] InputImagesTransforms = InputPositions.Select((x) => x.WCS).ToArray();
            IWCSProjection   OutputImageTransform  = OutputPosition.WCS;

            int OW = Output.GetLength(1);
            int OH = Output.GetLength(0);
            int i, j, k, c;

            double[]   MedValues = new double[Inputs.Length];
            PixelPoint pxp       = new PixelPoint();

            for (i = 0; i < OH; i++)
            {
                for (j = 0; j < OW; j++)
                {
                    pxp.X = j + OutputAlignment.X; pxp.Y = i + OutputAlignment.Y;
                    EquatorialPoint eqp = OutputImageTransform.GetEquatorialPoint(pxp);
                    c = 0;
                    for (k = 0; k < Inputs.Length; k++)
                    {
                        PixelPoint pyp = InputImagesTransforms[k].GetPixelPoint(eqp);
                        pyp.X = Math.Round(pyp.X - InputAlignments[k].X); pyp.Y = Math.Round(pyp.Y - InputAlignments[k].Y);
                        if (pyp.X < 0 || pyp.X >= Inputs[k].GetLength(1))
                        {
                            continue;
                        }
                        if (pyp.Y < 0 || pyp.Y >= Inputs[k].GetLength(0))
                        {
                            continue;
                        }
                        double dex = Inputs[k][(int)pyp.Y, (int)pyp.X];
                        MedValues[c] = dex;
                        c++;
                    }
                    if (c == 0)
                    {
                        continue;
                    }

                    Array.Sort(MedValues);
                    if (c % 2 == 1)
                    {
                        Output[i, j] = MedValues[c / 2];
                    }
                    else
                    {
                        Output[i, j] = MedValues[c / 2 - 1];
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Computes the second minimum value of multiple images.
        /// </summary>
        /// <param name="Inputs">Input data.</param>
        /// <param name="Output">Output data.</param>
        /// <param name="InputPositions">Input alignments.</param>
        /// <param name="OutputPosition">Output alignment.</param>
        /// <param name="empty">Dummy argument.</param>
        static void SeMinFilter(double[][,] Inputs, double[,] Output, SchedCore.ImageSegmentPosition[] InputPositions, SchedCore.ImageSegmentPosition OutputPosition, object empty)
        {
            PixelPoint[] InputAlignments = InputPositions.Select((x) => x.Alignment).ToArray();
            PixelPoint   OutputAlignment = OutputPosition.Alignment;

            IWCSProjection[] InputImagesTransforms = InputPositions.Select((x) => x.WCS).ToArray();
            IWCSProjection   OutputImageTransform  = OutputPosition.WCS;

            int        OW = Output.GetLength(1);
            int        OH = Output.GetLength(0);
            int        i, j, k;
            PixelPoint pxp = new PixelPoint();

            for (i = 0; i < OH; i++)
            {
                for (j = 0; j < OW; j++)
                {
                    double Min = double.MaxValue, Min2 = double.MaxValue;
                    pxp.X = j + OutputAlignment.X; pxp.Y = i + OutputAlignment.Y;
                    EquatorialPoint eqp = OutputImageTransform.GetEquatorialPoint(pxp);
                    for (k = 0; k < Inputs.Length; k++)
                    {
                        PixelPoint pyp = InputImagesTransforms[k].GetPixelPoint(eqp);
                        pyp.X = Math.Round(pyp.X - InputAlignments[k].X); pyp.Y = Math.Round(pyp.Y - InputAlignments[k].Y);
                        if (pyp.X < 0 || pyp.X >= Inputs[k].GetLength(1))
                        {
                            continue;
                        }
                        if (pyp.Y < 0 || pyp.Y >= Inputs[k].GetLength(0))
                        {
                            continue;
                        }
                        double dex = Inputs[k][(int)pyp.Y, (int)pyp.X];
                        if (dex < Min)
                        {
                            Min2 = Min; Min = dex; continue;
                        }
                        if (dex < Min2)
                        {
                            Min2 = dex;
                        }
                    }
                    Output[i, j] = Min2;
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>Pass-through constructor to Image.</summary>
 protected FitsImage(int Number, IWCSProjection Projection, HeaderTable Header, uint Width, uint Height) :
     base(Number, Projection, Header, Width, Height)
 {
 }