Пример #1
0
        public async Task <IMAGE_LABEL_INFO> ImproveLabel(FixedSizeImage?iActivated,
                                                          Image <Pixel>?img,
                                                          Image <byte>?gray,
                                                          IMAGE_LABEL_INFO label)
        {
            var ctx = img.Clone();

            Graphics <Pixel>?graphics = null;

            if (iActivated != null)
            {
                graphics = MoyskleyTech.ImageProcessing.Image.Graphics.FromImage(ctx);
                Application.Invoke((_, _1) =>
                {
                    iActivated.Image = ctx;
                });
            }
            //ctx.Width = gray.Width;
            //ctx.Height = gray.Height;
            graphics?.Clear(Pixels.White);
            graphics?.DrawImage(img, 0, 0);

            List <RectangleF> proposedBoxes = new List <RectangleF>();

            AttentionMapAnalizer c = new AttentionMapAnalizer();

            //Foreach config, keep proposed boxes
            foreach (var(p, wz) in StandardFunctions.ListXMeansModes(img))
            {
                proposedBoxes.AddRange(await c.Cluster(gray, graphics, p, wz));
                if (iActivated != null)
                {
                    Application.Invoke((_, _1) =>
                    {
                        iActivated.Image = ctx;
                    });
                }
                if (Program.verbose)
                {
                    Console.WriteLine("{2} MODE {0} {1}", p, wz, label.name);
                }
            }

            label = label.Clone();
            c.AdaptLabel(proposedBoxes, label, .9, .9, .25);
            if (iActivated != null)
            {
                Application.Invoke((_, _1) =>
                {
                    iActivated.Image = ctx;
                });
            }
            return(label);
        }
Пример #2
0
        /// <summary>
        /// Separate the current grayscale attention map into clusters
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public List <Cluster <Point3> > SeparateImage(Image <byte> image)
        {
            Image <double> img = image.ConvertUsing <double>((px) => px);

            var lst = new List <List <Point3> >();
            //Converts to 3D points
            var pts = (from x in Enumerable.Range(0, image.Width)
                       from y in Enumerable.Range(0, image.Height)
                       where img[x, y] > MIN_ATTENTION_PERBYTE
                       select new Point3(x, y, img[x, y])).ToList();

            Kmeans <Point3> .GetInitialMeans = StandardFunctions.GetRandomMeansFunction(img);

            Xmeans <Point3> xmeans   = new Xmeans <Point3>(pts);
            var             clusters = xmeans.Calculation();

            return(clusters);
        }
Пример #3
0
        /// <summary>
        /// Initialize the analyzer
        /// </summary>
        public void Init()
        {
            Kmeans <Point3> .GetWitnesses = (cPoints) =>
            {
                var sumX = cPoints.Sum(x => x.X);
                var sumY = cPoints.Sum(x => x.Y);
                var sumZ = cPoints.Sum(x => x.Z);

                var sumX2 = cPoints.Sum(x => x.X * x.X);
                var sumY2 = cPoints.Sum(x => x.Y * x.Y);
                var sumZ2 = cPoints.Sum(x => x.Z * x.Z);

                var squX = sumX2 - (sumX * sumX / (double)cPoints.Count());
                var squY = sumY2 - (sumY * sumY / (double)cPoints.Count());
                var squZ = sumZ2 - (sumZ * sumZ / (double)cPoints.Count());

                return(new double[] { squX, squY, squZ });
            };
            Kmeans <Point3> .GetDistance = StandardFunctions.Adapt <IVectorizable, IVectorizable, Point3, Point3, double, double>(
                StandardFunctions.MinkowskiDistance(3, new double[] { 1, 1, 1 }));
            Kmeans <Point3> .GetMean = StandardFunctions.GetMeanPt3;
        }