Пример #1
0
        private void btnConourArea_Click(object sender, EventArgs e)
        {
            int up = (int)nudCntrUp.Value;
            int dw = (int)nudCntrDw.Value;


            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
            var tempimg1 = WorkingImg.Clone();


            var colorimg = ColorMode == true ?  new Image <Bgr, byte>(RootImgColor.Data) : new Image <Bgr, byte>(RootImg.Bitmap);

            CvInvoke.FindContours(tempimg1, contours, null, RetrType.External, ChainApproxMethod.ChainApproxNone);


            List <double> arealist = new List <double>();

            for (int i = 0; i < contours.Size; i++)
            {
                double areaSize = CvInvoke.ContourArea(contours[i], false);  //  Find the area of contour
                if (areaSize >= dw && areaSize <= up)
                {
                    CvInvoke.DrawContours(colorimg, contours, i, new MCvScalar(14, 200, 40), 2);
                }
            }

            rtxLog.AppendText("Contour" + Environment.NewLine);
            RegistHisroty(WorkingImg, false);
            imageBox1.Image = colorimg;
            ///
        }
Пример #2
0
 private void btnLaplace_Click(object sender, EventArgs e)
 {
     WorkingImg = WorkingImg.Laplace(( int )nudLapla.Value).Convert <Gray, byte>();
     rtxLog.AppendText("btnLaplace_Click" + Environment.NewLine);
     RegistHisroty(WorkingImg, false);
     imageBox1.Image = WorkingImg;
 }
Пример #3
0
 private void btnInvThres_Click(object sender, EventArgs e)
 {
     WorkingImg = WorkingImg.InvThres(( int )nudINvThres.Value);
     rtxLog.AppendText("btnInvThres_Click" + Environment.NewLine);
     RegistHisroty(WorkingImg, false);
     imageBox1.Image = WorkingImg;
 }
Пример #4
0
        private void btnBox_Click(object sender, EventArgs e)
        {
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
            var tempimg1 = WorkingImg.Clone();
            var tempimg2 = WorkingImg.Clone();

            CvInvoke.FindContours(tempimg1, contours, null, RetrType.External, ChainApproxMethod.ChainApproxNone);
            Image <Bgr, byte> colorimg = tempimg2.Convert <Bgr, byte>();

            for (int i = 0; i < contours.Size; i++)
            {
                CvInvoke.DrawContours(colorimg, contours, i, new MCvScalar(14, 200, 40));
            }
            List <System.Drawing.Rectangle> PassBoxArr = new List <System.Drawing.Rectangle>();

            for (int i = 0; i < contours.Size; i++)
            {
                System.Drawing.Rectangle rc = CvInvoke.BoundingRectangle(contours[i]);
                PassBoxArr.Add(rc);
            }

            Parallel.For(0, PassBoxArr.Count, i =>
            {
                colorimg.Draw(PassBoxArr[i], new Bgr(20, 5, 165), 1);
            });

            rtxLog.AppendText("Box" + Environment.NewLine);
            RegistHisroty(WorkingImg);
        }
Пример #5
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            //var thres = (int)nudThres.Value;
            //Image<Gray, byte> imgoutput = new Image<Gray, byte>(WorkingImg.Data);
            //for (int i = 0; i < 20; i++)
            //{
            //    int thr = 190 + i;
            //    imgoutput = WorkingImg.ThresholdBinary(new Gray(thr), new Gray(255));
            //    imgoutput.Save(@"C:\Veeco_TestImg\Result" + "\\" + thr.ToString() + ".png");
            //}

            //rtxLog.AppendText( "ThresInv_Click  " + thres.ToString() + Environment.NewLine );
            //RegistHisroty( WorkingImg );


            var cluster               = new Clustering();
            var resultlist            = cluster.test(WorkingImg.ToBitmap());
            Image <Gray, byte> tetimg = new Image <Gray, byte>(resultlist["image"]);

            tetimg.Save(basepath + "Clustered.bmp");
            label1.Text = ((int)resultlist["center"][0][0]).ToString();
            label2.Text = ((int)resultlist["center"][1][0]).ToString();
            label3.Text = ((int)resultlist["center"][2][0]).ToString();
            WorkingImg  = tetimg;
            RegistHisroty(WorkingImg);
        }
Пример #6
0
 private void btnSimpleBlu_Click(object sender, EventArgs e)
 {
     WorkingImg = WorkingImg.SmoothBlur(( int )nudBlurKernelSize.Value, ( int )nudBlurKernelSize.Value);
     rtxLog.AppendText("btnSimpleBlu_Click" + Environment.NewLine);
     RegistHisroty(WorkingImg, false);
     imageBox1.Image = WorkingImg;
 }
Пример #7
0
 private void btnLevel_Click(object sender, EventArgs e)
 {
     //WorkingImg = WorkingImg.Brightness( ( double ) nudlevel_a .Value , ( double ) nudlevel_b.Value , ( double )nudlevel_s.Value , ( double )nudlevel_E.Value );
     WorkingImg = WorkingImg.Brightness(( double )nudlevel_a.Value, ( double )nudlevel_b.Value);
     rtxLog.AppendText($"btnLevel_Click alpha : {( double )nudlevel_a.Value }  ,  beta : {( double )nudlevel_b.Value } " + Environment.NewLine);
     RegistHisroty(WorkingImg);
 }
Пример #8
0
        private void squ_Click(object sender, EventArgs e)
        {
            var result = WorkingImg.MatchTemplate(TemplateImg, TemplateMatchingType.SqdiffNormed);

            WorkingImg = PaddingImage((255 - result * 255).Convert <Gray, byte>(), TemplateImg);
            rtxLog.AppendText("squ_Click" + Environment.NewLine);
            RegistHisroty(WorkingImg);
        }
Пример #9
0
        private void Corr_Click(object sender, EventArgs e)
        {
            rtxLog.AppendText("Corr_Click" + Environment.NewLine);
            var result = WorkingImg.MatchTemplate(TemplateImg, TemplateMatchingType.CcorrNormed);

            WorkingImg = PaddingImage((255 - 255 * result).Convert <Gray, byte>(), TemplateImg);
            RegistHisroty(WorkingImg);
        }
Пример #10
0
        private void ThresToZero_Click(object sender, EventArgs e)
        {
            var thres = (int)nudThres.Value;

            WorkingImg = WorkingImg.ThresholdToZero(new Gray(thres));
            rtxLog.AppendText("Thres_Click  " + thres.ToString() + Environment.NewLine);
            RegistHisroty(WorkingImg);
        }
Пример #11
0
        private void btnAdpThres2Zero_Click(object sender, EventArgs e)
        {
            WorkingImg = WorkingImg.ThresholdAdaptive(
                new Gray(255),
                AdaptiveThresholdType.GaussianC,
                ThresholdType.ToZero,
                ( int )nudAdpThresBlockSize.Value,
                new Gray(( int )nudAdpSubstractVal.Value));

            rtxLog.AppendText("btnAdpThres2Zero_Click" + Environment.NewLine);
            RegistHisroty(WorkingImg, false);
            imageBox1.Image = WorkingImg;
        }
Пример #12
0
 private void btnInverse_Click_1(object sender, EventArgs e)
 {
     //Parallel.For(0, WorkingImg.Height, j =>
     //{
     //    for (int i = 0; i < WorkingImg.Width; i++)
     //    {
     //        WorkingImg.Data[j, i, 0] = (byte)(255 - WorkingImg.Data[j, i, 0]);
     //    }
     //});
     WorkingImg = WorkingImg.Not();
     rtxLog.AppendText("btnInverse_Click  " + Environment.NewLine);
     RegistHisroty(WorkingImg);
 }
Пример #13
0
        private void btnBoxOnOri_Click(object sender, EventArgs e)
        {
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
            var temproot = RootImg.Clone();
            var tempimg1 = WorkingImg.Clone();
            var tempimg2 = WorkingImg.Clone();

            CvInvoke.FindContours(tempimg1, contours, null, RetrType.External, ChainApproxMethod.ChainApproxNone);
            Image <Bgr, byte> colorimg   = tempimg2.Convert <Bgr, byte>();
            Image <Bgr, byte> tempOriImg = temproot.Convert <Bgr, byte>();
            //for ( int i = 0 ; i < contours.Size ; i++ )
            //{
            //    CvInvoke.DrawContours( tempOriImg , contours , i , new MCvScalar( 14 , 200 , 40 ) );
            //}
            List <System.Drawing.Rectangle> PassBoxArr = new List <System.Drawing.Rectangle>();

            List <double> arealist = new List <double>();

            for (int i = 0; i < contours.Size; i++)
            {
                System.Drawing.Rectangle rc = CvInvoke.BoundingRectangle(contours[i]);
                double areasize             = rc.Width * rc.Height;
                //.Act( @ths => arealist.Add(@ths));
                arealist.Add(areasize);

                if (areasize > (double)nudAreaDw.Value || areasize < (double)nudAreaUp.Value)
                {
                    PassBoxArr.Add(rc); // Check Display
                }
            }

            var areaarr   = arealist.ToArray <double>();
            var histodata = areaarr.Map(@ths =>
                                        @ths.ShowHisto(30
                                                       , (int)@ths.Min()
                                                       , (int)@ths.Max()));

            float minv = (float)areaarr.Min();
            float maxv = (float)areaarr.Max();

            Form2 f2 = new Form2();

            f2.boxhisto.ClearHistogram();
            f2.boxhisto.AddHistogram(null, System.Drawing.Color.Black, histodata, 300, new float[] { minv, maxv });
            f2.boxhisto.Refresh();
            f2.Show();

            rtxLog.AppendText("Box on Origin" + Environment.NewLine);
            RegistHisroty(tempOriImg);
        }
Пример #14
0
 void History()
 {
     if (WorkingImg != null)
     {
         if (HistoryImg.Count < 20)
         {
             HistoryImg.Add(WorkingImg.Clone());
         }
         else
         {
             HistoryImg.RemoveAt(0);
             History();
         }
     }
 }
Пример #15
0
        private void btnCntrOrig_Click(object sender, EventArgs e)
        {
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
            var tempimg1 = WorkingImg.Clone();
            var tempimg2 = RootImg.Clone();

            CvInvoke.FindContours(tempimg1, contours, null, RetrType.External, ChainApproxMethod.ChainApproxNone);
            Image <Bgr, byte> colorimg = tempimg2.Convert <Bgr, byte>();

            for (int i = 0; i < contours.Size; i++)
            {
                CvInvoke.DrawContours(colorimg, contours, i, new MCvScalar(14, 250, 40), 2);
            }
            rtxLog.AppendText("Contour" + Environment.NewLine);
            RegistHisroty(WorkingImg, false);
            imageBox1.Image = colorimg;
        }
Пример #16
0
        private void btnConv_Click(object sender, EventArgs e)
        {
            float convratio = (float)nudConv.Value;
            var   kernel    = rtbConv.Text.Split('\n')
                              .Select(f => f.Split(',')
                                      .Select(s => float.Parse(s) / convratio)
                                      .ToArray())
                              .ToArray()
                              .ToMat();



            var fimg = WorkingImg.Convolution(new ConvolutionKernelF(kernel));

            WorkingImg = fimg.Convert <Gray, byte>();
            rtxLog.AppendText("btnConv_Click" + Environment.NewLine);
            RegistHisroty(WorkingImg, false);
            imageBox1.Image = WorkingImg;
        }
Пример #17
0
        private void btnFreak_Click(object sender, EventArgs e)
        {
            var temproot = RootImg.Clone();
            var tempimg1 = WorkingImg.Clone();
            Image <Bgr, byte> colorimg   = tempimg1.Convert <Bgr, byte>();
            Image <Bgr, byte> tempOriImg = temproot.Convert <Bgr, byte>();
            var f2d      = new Freak();
            var keypoint = f2d.Detect(WorkingImg);

            foreach (var point in keypoint)
            {
                System.Drawing.Rectangle rect = new Rectangle();
                rect.X      = (int)point.Point.X;
                rect.Y      = (int)point.Point.Y;
                rect.Width  = (int)point.Size;
                rect.Height = (int)point.Size;
                tempOriImg.Draw(rect, new Bgr(60, 200, 10), 2);
            }
            rtxLog.AppendText("btnFreak_Click" + Environment.NewLine);
            RegistHisroty(tempOriImg);
        }
Пример #18
0
 private void btnGamma_Click(object sender, EventArgs e)
 {
     WorkingImg._GammaCorrect((double)nudGamma.Value);
     rtxLog.AppendText("btnGamma_Click" + Environment.NewLine);
     RegistHisroty(WorkingImg);
 }
Пример #19
0
        private void btnHough_Click(object sender, EventArgs e)
        {
            imageBox1.Image = WorkingImg;
            var colimg = WorkingImg.Convert <Bgr, byte>();
            var data   = colimg.HoughLines(
                (int)nudhough1.Value,
                (int)nudhough2.Value,
                (int)nudhough3.Value,
                Math.PI / (int)nudhough4.Value,
                (int)nudhough5.Value,
                (double)nudhough6.Value,
                (double)nudhough7.Value);

            LineSegment2D avgLine  = new LineSegment2D();
            var           flatdata = data.Flatten();

            var selectedlines = flatdata.Where(x => x.P1.X > 50 && x.P1.Y > 50 && x.P2.X > 50 && x.P2.Y > 50).Select(x => x).ToArray();

            if (selectedlines.Count() != 0)
            {
                var result = selectedlines.Aggregate((f, s) =>
                {
                    var p1 = new System.Drawing.Point
                             (
                        f.P1.X + s.P1.X,
                        f.P1.Y + s.P1.Y
                             );

                    var p2 = new System.Drawing.Point
                             (
                        f.P2.X + s.P2.X,
                        f.P2.Y + s.P2.Y
                             );
                    return(new LineSegment2D(p1, p2));
                });

                avgLine = new LineSegment2D(
                    new System.Drawing.Point
                    (
                        result.P1.X / selectedlines.Count(),
                        result.P1.Y / selectedlines.Count()
                    ),
                    new System.Drawing.Point
                    (
                        result.P2.X / selectedlines.Count(),
                        result.P2.Y / selectedlines.Count()
                    )
                    );

                var selectedline = avgLine;

                colimg.Draw(selectedline, new Bgr(100, 200, 10), 2);

                imageBox1.Image = colimg;



                //rtxLog.AppendText( "btnBlur_Click" + Environment.NewLine );
                //RegistHisroty( WorkingImg , false );
                //imageBox1.Image = WorkingImg;
            }
        }
Пример #20
0
 private void btnEqualization_Click(object sender, EventArgs e)
 {
     WorkingImg._EqualizeHist();
     rtxLog.AppendText("btnEqualization_Click" + Environment.NewLine);
     RegistHisroty(WorkingImg);
 }
Пример #21
0
 private void btnNormalize3_Click(object sender, EventArgs e)
 {
     WorkingImg = WorkingImg.Normalize();
     rtxLog.AppendText($"btnNormalize3_Click " + Environment.NewLine);
     RegistHisroty(WorkingImg);
 }