Esempio n. 1
0
        public Bitmap alg2(Bitmap bm1, Bitmap bm2, image c, string path, string id)
        {
            List <dpoint> deltagroup = new List <dpoint>();

            int group = 1;

            int wid = Math.Min(bm1.Width, bm2.Width);
            int hgt = Math.Min(bm1.Height, bm2.Height);

            // Get the differences.
            int[,] diffs = new int[wid, hgt];

            int max_diff = 0;

            for (int x = 0; x < wid; x++)
            {
                for (int y = 0; y < hgt; y++)
                {
                    // Calculate the pixels' difference.
                    Color color1 = bm1.GetPixel(x, y);
                    Color color2 = bm2.GetPixel(x, y);
                    diffs[x, y] = (int)(
                        Math.Abs(color1.R - color2.R) +
                        Math.Abs(color1.G - color2.G) +
                        Math.Abs(color1.B - color2.B));
                    if (diffs[x, y] != 0 && diffs[x, y] < dif__)
                    {
                        diffs[x, y] = 0;
                    }
                    if (diffs[x, y] > max_diff)
                    {
                        max_diff = diffs[x, y];
                    }
                }
            }
            //max_diff = 255;
            dpoint  p;
            Boolean added = false;
            // Create the difference image.
            int    delta = 2;
            Bitmap bm3   = new Bitmap(wid, hgt);

            for (int x = 0; x < wid - delta; x += delta)
            {
                for (int y = 0; y < hgt - delta; y += delta)
                {
                    //if(diffs[x, y] != 0 )
                    if (diffs[x, y] != 0)
                    {
                        p       = new dpoint();
                        p.p.X   = x; p.p.Y = y;
                        p.value = diffs[x, y];
                        added   = false;
                        if (deltagroup.Count == 0)
                        {
                            p.group = group;
                            deltagroup.Add(p);
                            added = true;
                        }
                        foreach (dpoint dd in deltagroup)
                        {
                            if (canGroupingEdges(p.p.X, dd.p.X) && canGroupingEdges(dd.p.Y, p.p.Y))
                            {
                                p.group = dd.group;
                                deltagroup.Add(p);
                                added = true;
                                break;
                            }
                        }
                        if (added == false)
                        {
                            p.group = ++group;
                            deltagroup.Add(p);
                        }
                    }
                    hitsize = deltagroup.Count;
                    int clr = 255;

                    if (diffs[x, y] != 0)
                    {
                        clr = 255 - (int)(255.0 / max_diff * diffs[x, y]);
                    }

                    bm3.SetPixel(x, y, Color.FromArgb(clr, clr, clr));
                }
            }

            Graphics g  = Graphics.FromImage(bm2);
            string   st = "";
            Font     f  = new Font("Times New Roman", 24);

            for (int i = 1; i <= group; ++i)
            {
                foreach (dpoint dd in deltagroup)
                {
                    if (dd.group == i)
                    {
                        if (dd.p.Y > 80 && dd.p.Y < 200)
                        {
                            g.DrawString("*", f, Brushes.Blue, dd.p);
                        }
                        else
                        {
                            g.DrawString("*", f, Brushes.Green, dd.p);
                        }

                        st += "hit num(" + dd.group + ") in(" + dd.p.X + ", " + dd.p.Y + ") value: " + dd.value + ". " + Environment.NewLine;
                        i++;

                        //try
                        //{
                        //    //db.CreateMyOleDbDataReader("insert into hits ([id shot],[num of hits],[size of],[avarge]) values (" + this.GetcarFolderCounter(id) + "," + dd.p.Y + "," + dd.value + "," + dd.group + ");", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/asafl/Source/Repos/Final/comparlize/sqlouk.accdb");
                        //}
                        //catch (Exception v)
                        //{
                        //    continue;
                        //}
                    }
                }
            }


            // new pictureshow(bm1, bm3, bm2).Show();
            c.dplist.Add(deltagroup);
            try
            {
                System.IO.File.WriteAllText(@"" + path, contents: "" + st + Environment.NewLine + DateTime.Now + Environment.NewLine);
            }
            catch (Exception) { return(bm2); }
            return(bm2);
        }
Esempio n. 2
0
        public Bitmap alg(Bitmap bm1, Bitmap bm2, image c)
        {
            List <dpoint> deltagroup = new List <dpoint>();

            int group = 1;

            int wid = Math.Min(bm1.Width, bm2.Width);
            int hgt = Math.Min(bm1.Height, bm2.Height);

            // Get the differences.
            int[,] diffs = new int[wid, hgt];

            int max_diff = 0;

            for (int x = 0; x < wid; x++)
            {
                for (int y = 0; y < hgt; y++)
                {
                    // Calculate the pixels' difference.
                    Color color1 = bm1.GetPixel(x, y);
                    Color color2 = bm2.GetPixel(x, y);
                    diffs[x, y] = (int)(
                        Math.Abs(color1.R - color2.R) +
                        Math.Abs(color1.G - color2.G) +
                        Math.Abs(color1.B - color2.B));
                    if (diffs[x, y] > max_diff)
                    {
                        max_diff = diffs[x, y];
                    }
                }
            }
            //max_diff = 255;
            dpoint  p;
            Boolean added = false;
            // Create the difference image.
            Bitmap bm3 = new Bitmap(wid, hgt);

            for (int x = 0; x < wid; x++)
            {
                for (int y = 0; y < hgt; y++)
                {
                    if (diffs[x, y] != 0)
                    {
                        p       = new dpoint();
                        p.p.X   = x; p.p.Y = y;
                        p.value = diffs[x, y];
                        added   = false;
                        if (deltagroup.Count == 0)
                        {
                            p.group = group;
                            deltagroup.Add(p);
                            added = true;
                        }
                        foreach (dpoint dd in deltagroup)
                        {
                            if (canGroupingEdges(p.p.X, dd.p.X) && canGroupingEdges(dd.p.Y, p.p.Y))
                            {
                                p.group = dd.group;
                                deltagroup.Add(p);
                                added = true;
                                break;
                            }
                        }
                        if (added == false)
                        {
                            p.group = ++group;
                            deltagroup.Add(p);
                        }
                    }
                    int clr = 255;

                    if (diffs[x, y] != 0)
                    {
                        clr = 255 - (int)(255.0 / max_diff * diffs[x, y]);
                    }

                    bm3.SetPixel(x, y, Color.FromArgb(clr, clr, clr));
                }
            }

            Graphics g = Graphics.FromImage(bm3);

            Font f = new Font("Times New Roman", 6);

            for (int i = 1; i <= group; ++i)
            {
                foreach (dpoint dd in deltagroup)
                {
                    if (dd.group == i)
                    {
                        g.DrawString("hit(" + dd.p.X + "," + dd.p.Y + ") v" + dd.value + "|" + dd.group, f, Brushes.Red, dd.p);
                        //listBox1.Items.Add("hit num(" + dd.group + ") in(" + dd.p.X + ", " + dd.p.Y + ") value: " + dd.value + ". ");
                        i++;
                    }
                }
            }


            new pictureshow(bm1, bm3, bm2).Show();
            c.dplist.Add(deltagroup);
            return(bm3);
        }
Esempio n. 3
0
        private void button4_Click(object sender, EventArgs e)
        {
            DateTime start = DateTime.Now;

            this.Cursor = Cursors.WaitCursor;
            Application.DoEvents();

            // Load the images.
            Bitmap bm1 = (Bitmap)pictureBox1.Image;
            Bitmap bm2 = (Bitmap)pictureBox2.Image;

            // Make a difference image.
            int wid = Math.Min(bm1.Width, bm2.Width);
            int hgt = Math.Min(bm1.Height, bm2.Height);

            // Get the differences.
            int[,] diffs = new int[wid, hgt];

            int max_diff = 0;

            for (int x = 0; x < wid; x++)
            {
                for (int y = 0; y < hgt; y++)
                {
                    // Calculate the pixels' difference.
                    Color color1 = bm1.GetPixel(x, y);
                    Color color2 = bm2.GetPixel(x, y);
                    diffs[x, y] = (int)(
                        Math.Abs(color1.R - color2.R) +
                        Math.Abs(color1.G - color2.G) +
                        Math.Abs(color1.B - color2.B));
                    if (diffs[x, y] > max_diff)
                    {
                        max_diff = diffs[x, y];
                    }
                }
            }
            //max_diff = 255;
            dpoint  p;
            Boolean added = false;
            // Create the difference image.
            Bitmap bm3 = new Bitmap(wid, hgt);

            for (int x = 0; x < wid; x++)
            {
                for (int y = 0; y < hgt; y++)
                {
                    if (diffs[x, y] != 0)
                    {
                        p       = new dpoint();
                        p.p.X   = x; p.p.Y = y;
                        p.value = diffs[x, y];
                        added   = false;
                        if (deltagroup.Count == 0)
                        {
                            p.group = group;
                            deltagroup.Add(p);
                            added = true;
                        }
                        foreach (dpoint dd in deltagroup)
                        {
                            if (canGroupingEdges(p.p.X, dd.p.X) && canGroupingEdges(dd.p.Y, p.p.Y))
                            {
                                p.group = dd.group;
                                deltagroup.Add(p);
                                added = true;
                                break;
                            }
                        }
                        if (added == false)
                        {
                            p.group = ++group;
                            deltagroup.Add(p);
                        }
                    }
                    int clr = 255 - (int)(255.0 / max_diff * diffs[x, y]);
                    bm3.SetPixel(x, y, Color.FromArgb(clr, clr, clr));
                }
            }



            // Display the result.
            pictureBox3.Image    = bm3;
            pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
            Graphics     g = Graphics.FromImage(pictureBox3.Image);
            ListViewItem l;
            Font         f = new Font("Times New Roman", 6);

            for (int i = 1; i <= group; ++i)
            {
                foreach (dpoint dd in deltagroup)
                {
                    if (dd.group == i)
                    {
                        g.DrawString("hit(" + dd.p.X + "," + dd.p.Y + ") v" + dd.value + "|" + dd.group, f, Brushes.Red, dd.p);
                        listBox1.Items.Add("hit num(" + dd.group + ") in(" + dd.p.X + ", " + dd.p.Y + ") value: " + dd.value + ". ");
                        i++;
                    }
                }
            }

            DateTime end = DateTime.Now;

            label2.Text = (end - start).ToString();
            this.Cursor = Cursors.Default;
        }