コード例 #1
0
ファイル: Objects.cs プロジェクト: weepinglysmile/MMOI
        public static List<Point> GetObjects(CImage<double> background, out CImage<double> img, int r, double Q, int Xmin, int Xmax, bool crossing)
        {
            List<Point> obj = new List<Point>();
              int height = background.GetH;
              int width = background.GetW;
              img = background.Copy();
              int ObjNumber = GetNumber(height, width, Q, r);
              Random rndX = new Random(1);
              Random rndY = new Random(9);
              Random rndL = new Random(5);
              for (int i = 0; i < ObjNumber; i++)
              {
            int X, Y;
            int L = rndL.Next(Xmin, Xmax + 1);
            if (!crossing)
            {
              Point point = GetNewPoint(obj, rndX, rndY, height, width, r);
              obj.Add(point);
              X = point.x;
              Y = point.y;
            }
            else
            {
              X = rndX.Next(0, width + 1);
              Y = rndY.Next(0, height + 1);
              obj.Add(new Point(X, Y));
            }
              List<Point> points = new List<Point>();
              points = Bresenham.GetCircle(X,Y,r);
              points = Bresenham.GetFullCircle(points, new Point(X, Y));
              foreach (Point p in points)
              {
            int x = (p.x + width) % width;
            int y = (p.y + height) % height;
            img[x, y] = L;
              }

              }
              return obj;
        }
コード例 #2
0
        } //****************************** end ImageToBitmapNew ****************************************

        private void button2_Click(object sender, EventArgs e) // Impulse noise
        {
            ImpulseIm = new CImage(OrigIm.width, OrigIm.height, 24);

            ImpulseIm.Copy(OrigIm);

            int nbyte = ImpulseIm.N_Bits / 8;

            ImpulseIm.DeleteBit0(nbyte, this);

            int maxLight, minLight;

            int[] histo = new int[256];
            for (int i = 0; i < 256; i++)
            {
                histo[i] = 0;
            }

            int  light, index;
            byte R = 1, G = 1, B = 1;

            progressBar1.Step    = 1;
            progressBar1.Value   = 0;
            progressBar1.Maximum = 100;
            progressBar1.Visible = true;
            int jump, nStep = 15;

            if (ImpulseIm.height > 2 * nStep)
            {
                jump = ImpulseIm.height / nStep;
            }
            else
            {
                jump = 2;
            }
            for (int y = 0; y < ImpulseIm.height; y++)
            {
                if (y % jump == jump - 1)
                {
                    progressBar1.PerformStep();
                }
                for (int x = 0; x < ImpulseIm.width; x++) //======================================================
                {
                    index = x + y * ImpulseIm.width;      // Index of the pixel (x, y)
                    if (nbyte == 1)
                    {
                        light = ImpulseIm.Grid[index];
                    }
                    else
                    {
                        R     = (byte)(ImpulseIm.Grid[nbyte * index + 2] & 254);
                        G     = (byte)(ImpulseIm.Grid[nbyte * index + 1] & 254);
                        B     = (byte)(ImpulseIm.Grid[nbyte * index + 0] & 254);
                        light = MaxC(R, G, B);
                    }

                    if (light < 0)
                    {
                        light = 0;
                    }
                    if (light > 255)
                    {
                        light = 255;
                    }
                    histo[light]++;
                } //============================ end for (int x = 0; .. ========================================
            }     //============================== end for (int y = 0; .. ========================================
            for (maxLight = 255; maxLight > 0; maxLight--)
            {
                if (histo[maxLight] != 0)
                {
                    break;
                }
            }
            for (minLight = 0; minLight < 256; minLight++)
            {
                if (histo[minLight] != 0)
                {
                    break;
                }
            }

            CPnoise PN     = new CPnoise(histo, 1000, 4000);
            int     Number = 0;

            progressBar1.Visible = true;

            PN.Sort(ImpulseIm, histo, Number, pictureBox1.Width, pictureBox1.Height, this);

            int maxSizeD = (int)numericUpDown1.Value;
            int maxSizeL = (int)numericUpDown2.Value;

            PN.LightNoise(ref ImpulseIm, minLight, maxLight, maxSizeL, this);
            ImpulseIm.DeleteBit0(nbyte, this);

            PN.DarkNoise(ref ImpulseIm, minLight, maxLight, maxSizeD, this);

            progressBar1.Step = 1;
            int Len = nbyte * origBmp.Width * origBmp.Height;

            nStep = 10;
            jump  = Len / nStep;
            for (int i = 0; i < nbyte * origBmp.Width * origBmp.Height; i++)
            {
                if ((i % jump) == jump - 1)
                {
                    progressBar1.PerformStep();
                }
                if (ImpulseIm.Grid[i] == 252 || ImpulseIm.Grid[i] == 254)
                {
                    ImpulseIm.Grid[i] = 255;
                }
            }

            ImageToBitmapNew(ImpulseIm, BmpPictBox2); // ImpulseIm is always color image but BmpPictBox2 can be indexed
            pictureBox2.Image = BmpPictBox2;

            progressBar1.Visible = false;
            pictureBox2.Visible  = true;
            label3.Visible       = true;
            label3.Text          = "Impulse noise suppressed";
            button3.Visible      = true;
            label7.Text          = "Click 'Segment'";
            label7.Visible       = true;
            IMPULSE = true;
        } //********************************* end impulse noise *************************************