Exemple #1
0
        protected override MyImageD GetImageDInternal()
        {
            MyImageD imgd   = new MyImageD(imgd_provider.GetImageD());
            var      points = points_provider.GetPoints();

            LogPanel.Log($"[PlotPoints] {points.Count} points.");
            if (points.Count > 0)
            {
                MyImageD cross_img = new MyImageD(new double[imgd.data.Length], imgd);
                double
                    mn = points.Min(p => p.importance),
                    mx = points.Max(p => p.importance);
                foreach (var p in points.Reverse <ImagePoint>())
                {
                    Utils.GetHeatColor((p.importance - mn) / (mx - mn), out double r, out double g, out double b);
                    plot_cross(cross_img, p.x, p.y, r, g, b);
                }
                Parallel.For(0, imgd.height, i =>
                {
                    for (int j = 0; j < imgd.width; j++)
                    {
                        int k            = i * imgd.stride + j * 4;
                        double ratio     = cross_img.data[k + 3];
                        imgd.data[k + 0] = (1 - ratio) * imgd.data[k + 0] + cross_img.data[k + 0];
                        imgd.data[k + 1] = (1 - ratio) * imgd.data[k + 1] + cross_img.data[k + 1];
                        imgd.data[k + 2] = (1 - ratio) * imgd.data[k + 2] + cross_img.data[k + 2];
                    }
                });
            }
            return(imgd);
        }
Exemple #2
0
        protected override MyImageD GetImageDInternal()
        {
            MyImageD img_ans = new MyImageD(provider_base.GetImageD());

            scale_rgb_by_alpha(img_ans);
            foreach (var provider in providers)
            {
                MyImageD img = new MyImageD(provider.GetImageD());
                System.Diagnostics.Trace.Assert(img.width == img_ans.width && img.height == img_ans.height && img.stride == img_ans.stride);
                scale_rgb_by_alpha(img);
                Parallel.For(0, img.height, i =>
                {
                    for (int j = 0; j < img.width; j++)
                    {
                        int k = i * img.stride + j * 4;
                        img_ans.data[k + 0] += img.data[k + 0];
                        img_ans.data[k + 1] += img.data[k + 1];
                        img_ans.data[k + 2] += img.data[k + 2];
                        img_ans.data[k + 3] += img.data[k + 3];
                    }
                });
            }
            normalize_alpha(img_ans);
            return(img_ans);
        }
Exemple #3
0
            public bool sample_pixel(double x, double y, out double r, out double g, out double b)
            {
                // h = y*(r/sqrt(x^2+f^2))
                // a = center_direction+atan(x/f)
                // r = 1, f fixed, for each "h, a", find "x, y"
                MyImageD image = image_provider.GetImageD();

                return(image.sample(x - (this.center_x - 0.5 * image.width), y - (this.center_y - 0.5 * image.height), out r, out g, out b));
            }
Exemple #4
0
 private Tuple <double, double, int> get_displacement(int i, int j)
 {
     lock (get_displacement_cache_sync)
     {
         if (get_displacement_cache == null)
         {
             get_displacement_cache = new Tuple <double, double, int> [n, n];
         }
         if (get_displacement_cache[i, j] == null)
         {
             List <int> matches = points_match_list(i, j);
             List <Tuple <double, double, double, double> > candidates = new List <Tuple <double, double, double, double> >();
             for (int _ = 0; _ < matches.Count; _++)
             {
                 if (matches[_] != -1)
                 {
                     var p1 = points[i][_];
                     var p2 = points[j][matches[_]];
                     IImageD_Provider me = image_providers[i], other = image_providers[j];
                     candidates.Add(new Tuple <double, double, double, double>(
                                        p1.x - 0.5 * me.GetImageD().width,
                                        p1.y - 0.5 * me.GetImageD().height,
                                        p2.x - 0.5 * other.GetImageD().width,
                                        p2.y - 0.5 * other.GetImageD().height));
                 }
             }
             //LogPanel.Log($"candidate.count={candidates.Count}");
             var ans = Utils.VoteInliners(candidates, 10);
             get_displacement_cache[i, j] = new Tuple <double, double, int>(
                 ans.Average(_ =>
             {
                 var v = candidates[_];
                 return(v.Item1 - v.Item3);
             }),
                 ans.Average(_ =>
             {
                 var v = candidates[_];
                 return(v.Item2 - v.Item4);
             }), ans.Count);
         }
     }
     return(get_displacement_cache[i, j]);
 }
Exemple #5
0
        protected override MyMatrix GetMatrixInternal()
        {
            var image = provider.GetImageD();

            double[,] data = new double[image.height, image.width];
            System.Threading.Tasks.Parallel.For(0, data.GetLength(0), i =>
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    data[i, j] = image.data[i * image.stride + j * 4 + color_channel];
                }
            });
            return(new MyMatrix(data));
        }
Exemple #6
0
        protected override MyImageD GetImageDInternal()
        {
            MyImageD imgd = imgd_provider.GetImageD();
            int      width = (int)Math.Ceiling(imgd.width * scale), height = (int)Math.Ceiling(imgd.height * scale);
            int      stride = width * 4;
            MyImageD ans    = new MyImageD(new double[height * stride], width, height, stride, imgd.dpi_x, imgd.dpi_y, imgd.format, imgd.palette);

            Parallel.For(0, height, i => {
                for (int j = 0; j < width; j++)
                {//bgra
                    int k = i * stride + j * 4;
                    //x = width > 1 ? i / (width - 1) * (imgd.width - 1) : (imgd.width - 1) / 2;
                    //y = height > 1 ? i / (height - 1) * (imgd.height - 1) : (imgd.height - 1) / 2;
                    //imgd.sample(x, y, out double r, out double g, out double b);
                    imgd.sample(j / scale, i / scale, out double r, out double g, out double b);
                    //System.Diagnostics.Trace.WriteLine($"r={r}, g={g}, b={b}");
                    ans.data[k + 0] = b;
                    ans.data[k + 1] = g;
                    ans.data[k + 2] = r;
                    ans.data[k + 3] = 1;
                }
Exemple #7
0
 protected override MyMatrix GetMatrixInternal()
 {
     return(provider.GetImageD().ToMatrix());
 }
Exemple #8
0
 async void StartSimulation()
 {
     int kase_self = System.Threading.Interlocked.Increment(ref kase);
     await Task.Run(() =>
     {
         var images = source_image_panel.GetImages();
         List <IPointsProvider> points_providers = images.Select(i => new ImageD_Providers.ImageD_Cache(i.ToImageD()) as IImageD_Provider).Select(i => new PointsProviders.MSOP_DescriptorVector(new PointsProviders.HarrisCornerDetector(i), new MatrixProviders.GrayScale(i)) as IPointsProvider).ToList();
         List <IImageD_Provider> image_providers = images.Select((i, idx) => new ImageD_Providers.PlotPoints(new ImageD_Providers.ImageD_Cache(i.ToImageD()), points_providers[idx]) as IImageD_Provider).ToList();
         var global_viewer = new Func <PlaneImages>(() =>
         {
             return(new PlaneImages(image_providers, 5000, 600));
         })();
         int n = global_viewer.images.Count;
         image_container.Dispatcher.Invoke(() => image_container.Content = new ImageViewer(global_viewer, false));
         LogPanel.Log("searching features...");
         Parallel.For(0, n, i => image_providers[i].GetImageD());
         global_viewer.GetImageD();
         LogPanel.Log("matching...");
         var points           = points_providers.Select(pp => pp.GetPoints().Select(ps => (ps as ImagePoint <PointsProviders.MSOP_DescriptorVector.Descriptor>)).ToList()).ToList();
         var get_displacement = new Func <int, int, Tuple <double, double, int> >((i, j) =>
         {
             List <ImagePoint <PointsProviders.MSOP_DescriptorVector.Descriptor> > p1s = points[i], p2s = points[j];
             List <Tuple <double, double, double, double> > candidates = new List <Tuple <double, double, double, double> >();
             Parallel.For(0, p1s.Count, _ =>
             {
                 var p1 = p1s[_];
                 if (p1.content.try_match(p2s, out ImagePoint p2))
                 {
                     IImageD_Provider me = image_providers[i], other = image_providers[j];
                     lock (candidates) candidates.Add(new Tuple <double, double, double, double>(
                                                          p1.x - 0.5 * me.GetImageD().width,
                                                          p1.y - 0.5 * me.GetImageD().height,
                                                          p2.x - 0.5 * other.GetImageD().width,
                                                          p2.y - 0.5 * other.GetImageD().height));
                     //candidates.Add(Tuple.Create(p1.content.difference((p2 as ImagePoint<PointsProviders.MSOP_DescriptorVector.Descriptor>).content), p1.x, p1.y, p2.x, p2.y));
                 }
             });
             var ans = Utils.VoteInliners(candidates, 10);
             return(new Tuple <double, double, int>(
                        ans.Average(_ =>
             {
                 var v = candidates[_];
                 return v.Item3 - v.Item1;
             }),
                        ans.Average(_ =>
             {
                 var v = candidates[_];
                 return v.Item4 - v.Item2;
             }), ans.Count));
         });
         {
             bool[] vis = new bool[n];
             SortedSet <Tuple <int, int, Tuple <double, double, int> > > edge_list = new SortedSet <Tuple <int, int, Tuple <double, double, int> > >(new comparer1());
             var add_edges = new Action <int>(u =>
             {
                 Parallel.For(0, n, i =>
                 {
                     if (!vis[i])
                     {
                         var edge = new Tuple <int, int, Tuple <double, double, int> >(u, i, get_displacement(u, i));
                         lock (edge_list) edge_list.Add(edge);
                     }
                 });
             });
             vis[0] = true; global_viewer.images[0].set_position(0, 0);
             add_edges(0);
             while (edge_list.Count > 0)
             {
                 var edge = edge_list.First(); edge_list.Remove(edge);
                 if (vis[edge.Item2])
                 {
                     continue;
                 }
                 LogPanel.Log($"edge: {edge.Item1} → {edge.Item2}");
                 vis[edge.Item2] = true;
                 var u           = global_viewer.images[edge.Item1];
                 global_viewer.images[edge.Item2].set_position(u.center_x - edge.Item3.Item1, u.center_y - edge.Item3.Item2);
                 add_edges(edge.Item2);
             }
         }
         global_viewer.move_to_center();
         global_viewer.ResetSelf();
         global_viewer.GetImageD();
         LogPanel.Log("ok");
     });
 }