Example #1
0
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Console.WriteLine("Change");
            if (isChoosed == false)
            {
                MessageBox.Show("未选择图片");
            }
            label_funcName.Text = tabControl1.SelectedTab == null ? "empty" : tabControl1.SelectedTab.Text;
            if (tabControl1.SelectedTab == null)
            {
                return;
            }

            foreach (Control c in tabControl1.SelectedTab.Controls)
            {
                c.Enabled = isChoosed;
            }
            DialogResult dr = MessageBox.Show("是否保存修改结果?", "提示", MessageBoxButtons.OKCancel);

            if (dr == DialogResult.OK)
            {
                bitmap = new Bitmap(this.pictureBox_WorkPlace.Image);
            }
            else
            {
                this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width);
            }

            Page_Reset();
        }
Example #2
0
        private void button10_Click(object sender, EventArgs e)
        {
            Bitmap twoBmp;

            ProcessFunctions.TwoDivision_Change(bitmap, out twoBmp, 150);
            pictureBox2.Image = ToolFunctions.GetThumbnail((Bitmap)twoBmp.Clone(), pictureBox2.Height, pictureBox2.Width) as Image;
        }
Example #3
0
        private void Button_TwoD_Click(object sender, System.EventArgs e)
        {
            Bitmap twoVBmp;

            ProcessFunctions.TwoDivision_Change(bitmap, out twoVBmp, trackBar_DV.Value);
            this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)twoVBmp.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
        }
Example #4
0
        private void button_Sharpen_Click(object sender, EventArgs e)
        {
            Bitmap sharpenBmp;

            sharpenBmp = ProcessFunctions.SharpenFilter2(bitmap, trackBar_SV.Value);
            this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)sharpenBmp.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
        }
Example #5
0
        private void button12_Click(object sender, EventArgs e)
        {
            Size  picSize = new Size();
            Image temp    = ToolFunctions.GetInitThumbnail((Bitmap)bitmap.Clone(), pictureBox1.Height, pictureBox1.Width, out picSize) as Image;

            this.pictureBox1.Width = picSize.Width;
            //this.pictureBox1.Location = new Point(14 + 1097 / 2 - picSize.Width / 2, 25);
            this.pictureBox1.Image       = temp;
            this.pictureBox1.MouseClick += new MouseEventHandler((o, me) =>
            {
                ProcessFunctions.test_01(bitmap, me.Location, pictureBox1.Size);
                Console.WriteLine("location of Point:" + me.Location.X + "," + me.Location.Y);
                Bitmap outBmp;
                ProcessFunctions.setMosaic(bitmap, me.Location, pictureBox1.Size, 0, out outBmp);
                this.pictureBox1.Image = ToolFunctions.GetThumbnail(outBmp, pictureBox1.Height, pictureBox1.Width);
                //Console.WriteLine(pictureBox1.Width);
            });
            this.pictureBox1.MouseMove += new MouseEventHandler((o, me) =>
            {
                Bitmap outBmp;
                ProcessFunctions.setMosaic(bitmap, me.Location, pictureBox1.Size, 0, out outBmp);
                this.pictureBox1.Image = ToolFunctions.GetThumbnail(outBmp, pictureBox1.Height, pictureBox1.Width);
                bitmap = new Bitmap(this.pictureBox1.Image);
            });
        }
Example #6
0
        //get button
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                isChoosed = true;

                string path = openFileDialog1.FileName;
                bitmap     = (Bitmap)Image.FromFile(path);
                origin_bmp = (Bitmap)bitmap.Clone();
                reset();
                Size picSize = new Size();
                //pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
                Image temp = ToolFunctions.GetInitThumbnail((Bitmap)bitmap.Clone(), 723, 1097, out picSize) as Image;
                this.pictureBox_WorkPlace.Width    = picSize.Width;
                this.pictureBox_WorkPlace.Height   = picSize.Height;
                this.pictureBox_WorkPlace.Location = new Point(14 + 1097 / 2 - picSize.Width / 2, 25 + 723 / 2 - picSize.Height / 2);
                this.pictureBox_WorkPlace.Image    = temp;//ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width);
                gReal = Graphics.FromImage(this.pictureBox_WorkPlace.Image);
                if (tabControl1.SelectedTab == null)
                {
                    return;
                }
                foreach (Control control in tabControl1.SelectedTab.Controls)
                {
                    control.Enabled = true;
                }
            }
        }
Example #7
0
        private void Button_Mean_Filter_Click(object sender, System.EventArgs e)
        {
            Bitmap newBmp;

            ProcessFunctions.MeanFilter(noise_oldBmp, out newBmp);
            this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)newBmp.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
            noise_oldBmp = newBmp;
        }
Example #8
0
        private void button4_Click(object sender, EventArgs e)
        {
            Bitmap dest;

            pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
            ProcessFunctions.Grey_Change(bitmap, out dest, -5);
            pictureBox2.Image       = ToolFunctions.GetThumbnail((Bitmap)dest.Clone(), pictureBox2.Height, pictureBox2.Width) as Image;
            pictureBox1.MouseClick += PictureBox1_MouseClick;
        }
Example #9
0
 //clean button
 private void button2_Click_1(object sender, EventArgs e)
 {
     if (isChoosed == false)
     {
         return;
     }
     pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
     gReal = Graphics.FromImage(pictureBox_WorkPlace.Image);
 }
Example #10
0
        private void button3_Click(object sender, EventArgs e)
        {
            ProcessFunctions.Grey_Calculator(bmpHist, out maxPixel, ref countPixel);
            Grey_ScaleMapForm_Paint();
            pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
            Bitmap destB;

            ProcessFunctions.Balance(bitmap, out destB);
            pictureBox2.Image = ToolFunctions.GetThumbnail((Bitmap)destB.Clone(), pictureBox2.Height, pictureBox2.Width) as Image;
        }
Example #11
0
        private void button7_Click(object sender, EventArgs e)
        {
            Bitmap noiseBmp;

            ProcessFunctions.AddPepperSalt(bitmap, 0.2, 0.2, out noiseBmp);
            pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)noiseBmp.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
            //Bitmap cleanBmp;
            //ProcessFunctions.MedianFilter(noiseBmp, out cleanBmp);
            //pictureBox2.Image = ToolFunctions.GetThumbnail((Bitmap)cleanBmp.Clone(), pictureBox2.Height, pictureBox2.Width) as Image;
        }
Example #12
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         string path = openFileDialog1.FileName;
         bitmap            = (Bitmap)Image.FromFile(path);
         pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
         gReal             = Graphics.FromImage(pictureBox1.Image);
         pictureBox2.Image = pictureBox1.Image;
     }
 }
Example #13
0
        private void TrackBar_Grey_ValueChange(object sender, EventArgs e)
        {
            TrackBar self = (TrackBar)sender;
            Bitmap   dbitmap;

            ProcessFunctions.Grey_Change(bmpHist, out dbitmap, self.Value);
            this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)dbitmap.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
            //this.pictureBox_data.CreateGraphics().Clear(Color.White);
            ProcessFunctions.Grey_Calculator(dbitmap, out maxGreyPixel, ref countGreyPixel);
            Grey_Datagraphic_Layout();
        }
Example #14
0
        private void Get_Balance_Click(object sender, EventArgs e)
        {
            Button self = (Button)sender;
            Bitmap dbitmap;

            ProcessFunctions.Balance(bmpHist, out dbitmap);
            this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)dbitmap.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
            //this.pictureBox_data.CreateGraphics().Clear(Color.White);
            ProcessFunctions.Grey_Calculator(dbitmap, out maxGreyPixel, ref countGreyPixel);
            Grey_Datagraphic_Layout();
        }
Example #15
0
        private void button9_Click(object sender, EventArgs e)
        {
            Bitmap SharpenBmp;

            ProcessFunctions.SharpenFilter1(bitmap, out SharpenBmp);
            pictureBox2.Image = ToolFunctions.GetThumbnail((Bitmap)SharpenBmp.Clone(), pictureBox2.Height, pictureBox2.Width) as Image;
            Bitmap SharpenBmp2 = ProcessFunctions.SharpenFilter2(bitmap, 10F);

            pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)SharpenBmp2.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
            pictureBox3.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox3.Height, pictureBox3.Width) as Image;
        }
Example #16
0
 private void Reset_Click(object sender, EventArgs e)
 {
     if (isChoosed == false)
     {
         MessageBox.Show("未选择图片");
         return;
     }
     Page_Reset();
     bitmap = (Bitmap)origin_bmp.Clone();
     pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
 }
Example #17
0
        private void button5_Click(object sender, EventArgs e)
        {
            Bitmap srcm;

            pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)bitmap.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
            ProcessFunctions.Hsl_Change("s", -5, bitmap, out srcm);
            pictureBox2.Image = ToolFunctions.GetThumbnail((Bitmap)srcm.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
            Color c  = Color.FromArgb(15, 40, 200);
            Color c2 = ProcessFunctions.Hsl_Pixel_Change(c, "h", 24);

            //Console.WriteLine(hue + "," + sa + "," + l);
            Console.WriteLine(c.R + "," + c.G + "," + c.B + " ; " + c2.R + "," + c2.G + "," + c2.B);
            //pictureBox3.BackColor = Color.FromArgb(258, 2, -1);
        }
Example #18
0
        private void Button_Add_Pepper_Click(object sender, System.EventArgs e)
        {
            label_state.Text      = "Processing";
            label_state.BackColor = Color.Yellow;
            Button b = (Button)sender;

            b.Enabled = false;
            Bitmap newBmp;

            ProcessFunctions.AddPepperSalt(noise_oldBmp, ((float)trackBar_Pa.Value) / 10, ((float)trackBar_Pb.Value) / 10, out newBmp);
            this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)newBmp.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
            noise_oldBmp          = newBmp;
            b.Enabled             = true;
            label_state.Text      = "Finish";
            label_state.BackColor = Color.Green;
        }
Example #19
0
        private void button8_Click(object sender, EventArgs e)
        {
            //for (int i = 0; i < 1000; i++)
            //{
            //    double x = ProcessFunctions.GaussNoise(0,1);
            //    if(Math.Abs(x)>=1)
            //        Console.WriteLine(x);
            //}
            Bitmap noiseBmp;

            ProcessFunctions.AddGaussSalt(bitmap, out noiseBmp, new GaussParam(0, 1, 32));
            pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)noiseBmp.Clone(), pictureBox1.Height, pictureBox1.Width) as Image;
            Bitmap cleanBmp;

            ProcessFunctions.MeanFilter(noiseBmp, out cleanBmp);
            pictureBox2.Image = ToolFunctions.GetThumbnail((Bitmap)cleanBmp.Clone(), pictureBox2.Height, pictureBox2.Width) as Image;
        }
Example #20
0
        public static double GaussNoise(double u, double d)
        {
            double u1, u2, z, x;

            //Random ram = new Random();
            if (d <= 0)
            {
                return(u);
            }
            u1 = (new Random(ToolFunctions.GetRandomSeed())).NextDouble();
            u2 = (new Random(ToolFunctions.GetRandomSeed())).NextDouble();

            z = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2);

            x = u + d * z;
            return(x);
        }
Example #21
0
        private void button6_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            ToolFunctions.ClearEvent(this.pictureBox_WorkPlace, "MouseDown");
            ToolFunctions.ClearEvent(this.pictureBox_WorkPlace, "MouseUp");

            if (btn.Text == "使用吸管")
            {
                btn.Text = "使用画笔";
                this.pictureBox_WorkPlace.MouseDown += PictureBox_WorkPlace_MouseDown_GetColor;
                this.button_Mosaic.Enabled           = false;
            }
            else if (btn.Text == "使用画笔")
            {
                btn.Text = "使用吸管";
                this.pictureBox_WorkPlace.MouseDown += pictureBox2_Paint_MouseDown;
                this.pictureBox_WorkPlace.MouseUp   += pictureBox2_Paint_MouseUp;
                this.button_Mosaic.Enabled           = true;
            }
        }
Example #22
0
        private void button_Add_Gauss_Click(object sender, EventArgs e)
        {
            label_state.Text      = "Processing";
            label_state.BackColor = Color.Yellow;
            Button b = (Button)sender;

            b.Enabled = false;
            Bitmap     newBmp;
            GaussParam g = new GaussParam(((float)trackBar_Nu.Value) / 10, ((float)trackBar_Nd.Value) / 10, trackBar_Nk.Value);
            Task       t = new Task(() => {
                ProcessFunctions.AddGaussSalt(noise_oldBmp, out newBmp, g);
                this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)newBmp.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
                noise_oldBmp = newBmp;
            });

            t.Start();
            t.Wait();

            b.Enabled             = true;
            label_state.Text      = "Finish";
            label_state.BackColor = Color.Green;
        }
Example #23
0
        private void Hsi_H_ValueChanged(object sender, EventArgs e)
        {
            TrackBar self = (TrackBar)sender;
            Bitmap   dbitmap;

            HV = self.Value;
            if (1 == HSI_FLAG)
            {
                ProcessFunctions.Hsl_Change("h", HV, (Bitmap)Hsi_tempBmp.Clone(), out dbitmap);
            }
            else
            {
                Bitmap dbitmap1;
                ProcessFunctions.Hsl_Change("l", IV, (Bitmap)Hsi_bitmap.Clone(), out dbitmap1);
                Bitmap dbitmap2;
                ProcessFunctions.Hsl_Change("S", SV, (Bitmap)dbitmap1.Clone(), out dbitmap2);
                Hsi_tempBmp = dbitmap2;
                ProcessFunctions.Hsl_Change("h", HV, (Bitmap)Hsi_tempBmp.Clone(), out dbitmap);
            }
            this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)dbitmap.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width) as Image;
            Hsi_nowBmp = dbitmap;
        }
Example #24
0
        private int OpenT()
        {
            String filename = "F:\\b.png";

            //Mat I = (Bitmap)Image.FromFile(filename);
            Mat I      = new Mat(filename, ImreadModes.Color);
            Mat X      = new Mat();
            Mat padded = new Mat();                 //以0填充输入图像矩阵
            //Cv2.GetOptimalDFTSize();
            int m = Cv2.GetOptimalDFTSize(I.Rows);
            int n = Cv2.GetOptimalDFTSize(I.Cols);


            //填充输入图像I,输入矩阵为padded,上方和左方不做填充处理
            Cv2.CopyMakeBorder(I, padded, 0, m - I.Rows, 0, n - I.Cols, BorderTypes.Constant);


            pictureBox1.Image = ToolFunctions.GetThumbnail(X.ToBitmap(), pictureBox1.Height, pictureBox1.Width);



            return(0);
        }
Example #25
0
        private void pictureBox2_Paint_MouseMove(object sender, MouseEventArgs e)
        {
            if (isChoosed == false)
            {
                return;
            }
            if (in_box_flag == 1 && pen_type == 0)
            {
                //Console.WriteLine(e.Location.X + "," + e.Location.Y + "  " + flag);
                if (lastP.X == -1)
                {
                    Console.WriteLine("in");
                    lastP = e.Location;
                    return;
                }
                else
                {
                    SolidBrush solidBrush = new SolidBrush(choose_color);

                    Pen pen = new Pen(solidBrush, trackBar_Paint.Value);


                    myDrawLine(pen, lastP, e.Location);

                    lastP = e.Location;
                }
            }
            if (in_box_flag == 1 && pen_type == 1)
            {
                Bitmap dstBmp;

                ProcessFunctions.setMosaic(bitmap, e.Location, pictureBox_WorkPlace.Size, trackBar_Paint.Value, out dstBmp);
                //Console.WriteLine("Image size:"+ this.pictureBox_WorkPlace.Image.Width);
                this.pictureBox_WorkPlace.Image = ToolFunctions.GetThumbnail((Bitmap)dstBmp.Clone(), pictureBox_WorkPlace.Height, pictureBox_WorkPlace.Width);
                bitmap = new Bitmap(this.pictureBox_WorkPlace.Image);
            }
        }
Example #26
0
 private void Page_Reset()
 {
     ToolFunctions.ClearEvent(pictureBox_WorkPlace, "MouseMove");
     ToolFunctions.ClearEvent(pictureBox_WorkPlace, "MouseClick");
     ToolFunctions.ClearEvent(pictureBox_WorkPlace, "MouseUp");
     label_funcName.Text = tabControl1.SelectedTab == null?"empty": tabControl1.SelectedTab.Text;
     if (isChoosed == true)
     {
         if (tabControl1.SelectedTab == tabPage_Paint)
         {
             Paint_Page_Init();
             Console.WriteLine("in paint");
         }
         else if (tabControl1.SelectedTab == tabPage_Grey)
         {
             Grey_Page_Init();
             Console.WriteLine("in grey");
         }
         else if (tabControl1.SelectedTab == tabPage_Hsi)
         {
             Hsi_Page_Init();
         }
     }
 }
Example #27
0
        public static void AddPepperSalt(Bitmap srcBmp, double Pa, double Pb, out Bitmap dstBmp)
        {
            // Bitmap pic = (Bitmap)Bitmap.FromFile(filename, false);
            dstBmp = srcBmp;
            Bitmap          tmpBmp  = (Bitmap)dstBmp.Clone();
            double          P       = Pb / (1 - Pa);//程序要,为了得到一个概率Pb事件
                        int width   = dstBmp.Width;
            int             height  = dstBmp.Height;
            Random          rand    = new Random(ToolFunctions.GetRandomSeed());
            Rectangle       rt      = new Rectangle(0, 0, srcBmp.Width, srcBmp.Height);
            BitmapData      bmpData = tmpBmp.LockBits(rt, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            Task            t1      = new Task(() =>
            {
                unsafe
                {
                    for (int i = 0; i < bmpData.Height / 2; i++)
                    {
                        byte *ptr = (byte *)bmpData.Scan0 + i * bmpData.Stride;
                        for (int j = 0; j < bmpData.Width / 2; j++)
                        {
                            double probility = rand.NextDouble();
                            rand.NextDouble();
                            if (probility == 0)
                            {
                                rand = new Random(ToolFunctions.GetRandomSeed());
                                //probility = rand.NextDouble();
                            }
                            if (probility < Pa)
                            {
                                //noiseC = Color.White;//有Pa概率 噪声设为最大值
                                *(ptr + j * 3)     = 255; //B
                                *(ptr + j * 3 + 1) = 255; //G
                                *(ptr + j * 3 + 2) = 255; //R
                                //Console.WriteLine("probility:"+probility);
                            }
                            else
                            {
                                double temp = rand.NextDouble();
                                if (temp < P)               //有1 - Pa的几率到达这里,再乘以 P ,刚好等于Pb
                                {
                                    *(ptr + j * 3)     = 0; //B
                                    *(ptr + j * 3 + 1) = 0; //G
                                    *(ptr + j * 3 + 2) = 0; //R
                                }
                            }
                        }
                    }
                }
                //tmpBmp.UnlockBits(bmpData);
            });
            Task t2 = new Task(() =>
            {
                //BitmapData bmpData = tmpBmp.LockBits(rt, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                unsafe
                {
                    for (int i = bmpData.Height / 2; i < bmpData.Height; i++)
                    {
                        byte *ptr = (byte *)bmpData.Scan0 + i * bmpData.Stride;
                        for (int j = 0; j < bmpData.Width / 2; j++)
                        {
                            double probility = rand.NextDouble();
                            if (probility == 0)
                            {
                                rand = new Random(ToolFunctions.GetRandomSeed());
                                //probility = rand.NextDouble();
                            }
                            if (probility < Pa)
                            {
                                //noiseC = Color.White;//有Pa概率 噪声设为最大值
                                *(ptr + j * 3)     = 255; //B
                                *(ptr + j * 3 + 1) = 255; //G
                                *(ptr + j * 3 + 2) = 255; //R
                                                          //Console.WriteLine("probility:"+probility);
                            }
                            else
                            {
                                double temp = rand.NextDouble();
                                if (temp < P)               //有1 - Pa的几率到达这里,再乘以 P ,刚好等于Pb
                                {
                                    *(ptr + j * 3)     = 0; //B
                                    *(ptr + j * 3 + 1) = 0; //G
                                    *(ptr + j * 3 + 2) = 0; //R
                                }
                            }
                        }
                    }
                }
                //tmpBmp.UnlockBits(bmpData);
            });
            Task t3 = new Task(() =>
            {
                //BitmapData bmpData = tmpBmp.LockBits(rt, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                unsafe
                {
                    for (int i = 0; i < bmpData.Height / 2; i++)
                    {
                        byte *ptr = (byte *)bmpData.Scan0 + i * bmpData.Stride;
                        for (int j = bmpData.Width / 2; j < bmpData.Width; j++)
                        {
                            double probility = rand.NextDouble();
                            if (probility == 0)
                            {
                                rand = new Random(ToolFunctions.GetRandomSeed());
                                //probility = rand.NextDouble();
                            }
                            if (probility < Pa)
                            {
                                //noiseC = Color.White;//有Pa概率 噪声设为最大值
                                *(ptr + j * 3)     = 255; //B
                                *(ptr + j * 3 + 1) = 255; //G
                                *(ptr + j * 3 + 2) = 255; //R
                                                          //Console.WriteLine("probility:"+probility);
                            }
                            else
                            {
                                double temp = rand.NextDouble();
                                if (temp < P)               //有1 - Pa的几率到达这里,再乘以 P ,刚好等于Pb
                                {
                                    *(ptr + j * 3)     = 0; //B
                                    *(ptr + j * 3 + 1) = 0; //G
                                    *(ptr + j * 3 + 2) = 0; //R
                                }
                            }
                        }
                    }
                }
                //tmpBmp.UnlockBits(bmpData);
            });
            Task t4 = new Task(() =>
            {
                //BitmapData bmpData = tmpBmp.LockBits(rt, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                unsafe
                {
                    int i = bmpData.Height / 2;

                    for (; i < bmpData.Height; i++)
                    {
                        byte *ptr = (byte *)bmpData.Scan0 + i * bmpData.Stride;
                        for (int j = bmpData.Width / 2; j < bmpData.Width; j++)
                        {
                            double probility = rand.NextDouble();
                            if (probility == 0)
                            {
                                rand = new Random(ToolFunctions.GetRandomSeed());
                                //probility = rand.NextDouble();
                            }
                            if (probility < Pa)
                            {
                                //noiseC = Color.White;//有Pa概率 噪声设为最大值
                                *(ptr + j * 3)     = 255; //B
                                *(ptr + j * 3 + 1) = 255; //G
                                *(ptr + j * 3 + 2) = 255; //R
                                                          //Console.WriteLine("probility:"+probility);
                            }
                            else
                            {
                                double temp = rand.NextDouble();
                                if (temp < P)               //有1 - Pa的几率到达这里,再乘以 P ,刚好等于Pb
                                {
                                    *(ptr + j * 3)     = 0; //B
                                    *(ptr + j * 3 + 1) = 0; //G
                                    *(ptr + j * 3 + 2) = 0; //R
                                }
                            }
                        }
                    }
                    Console.WriteLine("over t4:" + i);
                }
                //tmpBmp.UnlockBits(bmpData);
            });


            t1.Start();
            t2.Start();
            t3.Start();
            t4.Start();
            //t1.Wait();

            //t2.Wait();
            Task.WaitAll(t1, t2, t3, t4);
            tmpBmp.UnlockBits(bmpData);
            dstBmp = tmpBmp;
            //for (int i = 0; i < height; i++)
            //{
            //    for (int j = 0; j < width; j++)
            //    {
            //        Color noiseC = dstBmp.GetPixel(j, i);
            //        double probility = rand.NextDouble();
            //        if (probility < Pa)
            //        {
            //            noiseC = Color.White;//有Pa概率 噪声设为最大值
                        //        }
                        //        else
                        //        {
                        //            double temp = rand.NextDouble();
                        //            if (temp < P)//有1 - Pa的几率到达这里,再乘以 P ,刚好等于Pb
                        //                noiseC = Color.Black;
                        //        }

            //        Color color = noiseC;
            //        dstBmp.SetPixel(j, i, color);
            //    }
            //}
        }
 public Form_ShowOrigin(Bitmap bitmap)
 {
     InitializeComponent();
     ori_bmp = bitmap;
     this.pictureBox1.Image = ToolFunctions.GetThumbnail((Bitmap)ori_bmp.Clone(), pictureBox1.Height, pictureBox1.Width);
 }