Forráskód Böngészése

Merge branch 'dev' into Release2.4

gsp 3 éve
szülő
commit
e6fb0d4bd9

+ 7 - 2
OTSIncAReportApp/1-UI/Control_Graph/Controls/Control_DrawDistrbutionImageAndBSE.cs

@@ -1191,7 +1191,7 @@ namespace OTSIncAReportGraph.Controls
                 else if(m_ParticleSegmentation.IsParticleSegmentation)
                 {
                     m_ParticleSegmentation.EndPoint = e.Location;
-                    DialogResult res = MessageBox.Show(table["str11"].ToString());
+                    DialogResult res = MessageBox.Show(table["str11"].ToString(), "", MessageBoxButtons.OKCancel);
                     if (res == DialogResult.OK)
                     {
                         m_ReportFun.m_ParticleSegmentation = m_ParticleSegmentation;
@@ -2191,7 +2191,12 @@ namespace OTSIncAReportGraph.Controls
             return x;
         }
 
-        private void ParticleSegmentation_Click(object sender, EventArgs e)
+        //private void ParticleSegmentation_Click(object sender, EventArgs e)
+        //{
+        //    Particle_Segmentation();
+        //}
+
+        private void 分割颗粒ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             Particle_Segmentation();
         }

+ 16 - 7
OTSIncAReportApp/1-UI/Control_Graph/Controls/Control_DrawDistrbutionImageAndBSE.designer.cs

@@ -35,6 +35,7 @@
             this.toolStripMenuItem_copyimage = new System.Windows.Forms.ToolStripMenuItem();
             this.ExportoriginalspliceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.ToolStripMenuItemDelete_Particle = new System.Windows.Forms.ToolStripMenuItem();
+            this.分割颗粒ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.CMenuStrip.SuspendLayout();
             this.SuspendLayout();
             // 
@@ -46,15 +47,16 @@
             this.ToolStripMenuItem_movesempoint,
             this.toolStripMenuItem_copyimage,
             this.ExportoriginalspliceToolStripMenuItem,
-            this.ToolStripMenuItemDelete_Particle});
+            this.ToolStripMenuItemDelete_Particle,
+            this.分割颗粒ToolStripMenuItem});
             this.CMenuStrip.Name = "contextMenuStrip1";
-            this.CMenuStrip.Size = new System.Drawing.Size(219, 154);
+            this.CMenuStrip.Size = new System.Drawing.Size(219, 206);
             // 
             // ToolStripMenuItem_selected
             // 
             this.ToolStripMenuItem_selected.Image = global::OTSIncAReportApp.Properties.Resources.选择颗粒;
             this.ToolStripMenuItem_selected.Name = "ToolStripMenuItem_selected";
-            this.ToolStripMenuItem_selected.Size = new System.Drawing.Size(253, 30);
+            this.ToolStripMenuItem_selected.Size = new System.Drawing.Size(218, 30);
             this.ToolStripMenuItem_selected.Text = "选择颗粒";
             this.ToolStripMenuItem_selected.Click += new System.EventHandler(this.ToolStripMenuItem_selected_Click);
             // 
@@ -62,7 +64,7 @@
             // 
             this.ToolStripMenuItem_movesempoint.Image = global::OTSIncAReportApp.Properties.Resources.移动SEM到当前位置;
             this.ToolStripMenuItem_movesempoint.Name = "ToolStripMenuItem_movesempoint";
-            this.ToolStripMenuItem_movesempoint.Size = new System.Drawing.Size(253, 30);
+            this.ToolStripMenuItem_movesempoint.Size = new System.Drawing.Size(218, 30);
             this.ToolStripMenuItem_movesempoint.Text = "移动SEM至颗粒所在位置";
             this.ToolStripMenuItem_movesempoint.Click += new System.EventHandler(this.ToolStripMenuItem_movesempoint_Click);
             // 
@@ -70,7 +72,7 @@
             // 
             this.toolStripMenuItem_copyimage.Image = global::OTSIncAReportApp.Properties.Resources.复制图像;
             this.toolStripMenuItem_copyimage.Name = "toolStripMenuItem_copyimage";
-            this.toolStripMenuItem_copyimage.Size = new System.Drawing.Size(253, 30);
+            this.toolStripMenuItem_copyimage.Size = new System.Drawing.Size(218, 30);
             this.toolStripMenuItem_copyimage.Text = "导出原图拼接图";
             this.toolStripMenuItem_copyimage.Click += new System.EventHandler(this.toolStripMenuItem_copyimage_Click);
             // 
@@ -78,7 +80,7 @@
             // 
             this.ExportoriginalspliceToolStripMenuItem.Image = global::OTSIncAReportApp.Properties.Resources.复制图像;
             this.ExportoriginalspliceToolStripMenuItem.Name = "ExportoriginalspliceToolStripMenuItem";
-            this.ExportoriginalspliceToolStripMenuItem.Size = new System.Drawing.Size(253, 30);
+            this.ExportoriginalspliceToolStripMenuItem.Size = new System.Drawing.Size(218, 30);
             this.ExportoriginalspliceToolStripMenuItem.Text = "导出原图拼接分类图";
             this.ExportoriginalspliceToolStripMenuItem.Click += new System.EventHandler(this.ExportoriginalspliceToolStripMenuItem_Click);
             // 
@@ -88,7 +90,13 @@
             this.ToolStripMenuItemDelete_Particle.Size = new System.Drawing.Size(218, 30);
             this.ToolStripMenuItemDelete_Particle.Text = "Delete particles";
             this.ToolStripMenuItemDelete_Particle.Click += new System.EventHandler(this.ToolStripMenuItemDelete_Particle_Click);
-           
+            // 
+            // 分割颗粒ToolStripMenuItem
+            // 
+            this.分割颗粒ToolStripMenuItem.Name = "分割颗粒ToolStripMenuItem";
+            this.分割颗粒ToolStripMenuItem.Size = new System.Drawing.Size(218, 30);
+            this.分割颗粒ToolStripMenuItem.Text = "分割颗粒";
+            this.分割颗粒ToolStripMenuItem.Click += new System.EventHandler(this.分割颗粒ToolStripMenuItem_Click);
             // 
             // Control_DrawDistrbutionImageAndBSE
             // 
@@ -113,5 +121,6 @@
         private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem_copyimage;
         private System.Windows.Forms.ToolStripMenuItem ExportoriginalspliceToolStripMenuItem;
         private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemDelete_Particle;
+        private System.Windows.Forms.ToolStripMenuItem 分割颗粒ToolStripMenuItem;
     }
 }

+ 112 - 99
OTSIncAReportApp/1-UI/Control_Graph/OTSIncAReportGraphFuncation/OTSImageDisHelp.cs

@@ -697,10 +697,18 @@ namespace OTSIncAReportGraph.OTSIncAReportGraphFuncation
                 return false;
             }
         }
+
+        /// <summary>
+        /// 获取分离颗粒方法
+        /// </summary>
+        /// <param name="startPoint"></param>
+        /// <param name="endPoint"></param>
+        /// <returns></returns>
         public bool GetSplitPartFun(Point startPoint, Point endPoint)
         {
             try
             {
+                CImageHandler m_ImagePro = new CImageHandler();
                 Particle particle1 = (Particle)CloneObject(m_ParticleSegmentation.ParticleData);
                 Particle particle2 = (Particle)CloneObject(m_ParticleSegmentation.ParticleData);
                 Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
@@ -710,111 +718,75 @@ namespace OTSIncAReportGraph.OTSIncAReportGraphFuncation
                 int width = int.Parse(ImageResolution.Split('_')[1]);
                 int height = int.Parse(ImageResolution.Split('_')[2]);
                 double dPixelSize = d_scanFieldSize_width / width;
-                Mat mat = new Mat(height, width, MatType.CV_8UC1, Scalar.Black);//黑色底图
-                Mat matBse = new Mat(resultFile.List_OTSField[particle1.FieldId].FieldImage, ImreadModes.Grayscale);//原图
-                foreach (Segment segment in m_ParticleSegmentation.ParticleData.SegmentList)
-                {
-                    Cv2.Line(mat, new OpenCvSharp.Point(segment.Start, segment.Height), new OpenCvSharp.Point(segment.Start + segment.Length, segment.Height), Scalar.White, 1, LineTypes.AntiAlias);
-                }
-                Cv2.Line(mat, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, Scalar.Black, 2, LineTypes.AntiAlias);
-                Mat labelMat = new Mat();
-                Mat stats = new Mat();//点的信息
-                Mat centroids = new Mat();//质心的信息
-                int nonenum = Cv2.ConnectedComponentsWithStats(mat, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
-                //暂时只分割成两个颗粒
-                if (nonenum != 3)
-                {
-                    log.Trace("(GetSplitPartFun) More than two particle");
-                    return false;
-                }
-                //寻找坐标点
-                List<Point> points1 = new List<Point>();
-                List<Point> points2 = new List<Point>();
-                List<int> aveGray1 = new List<int>();
-                List<int> aveGray2 = new List<int>();
-                for (int k = 0; k < labelMat.Height; k++)
+
+                using (Mat mat = new Mat(height, width, MatType.CV_8UC1, Scalar.Black))//黑色底图
+                using (Mat labelMat = new Mat())
+                using (Mat stats = new Mat())
+                using (Mat centroids = new Mat())
+                using (Mat matBse = new Mat(resultFile.List_OTSField[particle1.FieldId].FieldImage, ImreadModes.Grayscale))
                 {
-                    for (int j = 0; j < labelMat.Width; j++)
+                    foreach (Segment segment in m_ParticleSegmentation.ParticleData.SegmentList)
                     {
-                        int no = labelMat.Get<int>(k, j);
-                        if (no == 1)
-                        {
-                            points1.Add(new Point(j, k));
-                            aveGray1.Add(matBse.Get<byte>(k, j));
-                        }
-                        else if (no == 2)
+                        Cv2.Line(mat, new OpenCvSharp.Point(segment.Start, segment.Height), new OpenCvSharp.Point(segment.Start + segment.Length, segment.Height), Scalar.White, 1, LineTypes.AntiAlias);
+                    }
+                    //寻找坐标点
+                    List<Point> points1 = new List<Point>();
+                    List<Point> points2 = new List<Point>();
+                    List<int> aveGray1 = new List<int>();
+                    List<int> aveGray2 = new List<int>();
+                    for (int k = 0; k < mat.Height; k++)
+                    {
+                        for (int j = 0; j < mat.Width; j++)
                         {
-                            points2.Add(new Point(j, k));
-                            aveGray2.Add(matBse.Get<byte>(k, j));
+                            if (mat.Get<int>(k, j) != 0)
+                            {
+                                int side = (startPoint.X - j) * (endPoint.Y - k) - (startPoint.Y - k) * (endPoint.X - j);
+                                if (side >= 0)//区分像素位置
+                                {
+                                    points1.Add(new Point(j, k));
+                                    aveGray1.Add(matBse.Get<byte>(k, j));
+                                }
+                                else
+                                {
+                                    points2.Add(new Point(j, k));
+                                    aveGray2.Add(matBse.Get<byte>(k, j));
+                                }
+                            }
                         }
                     }
-                }
-                mat.Dispose();
-                matBse.Dispose();
-                //处理Segment
-                List<COTSSegmentClr> SegmentClrList1 = new List<COTSSegmentClr>();
-                List<COTSSegmentClr> SegmentClrList2 = new List<COTSSegmentClr>();
-                List<Segment> SegmentList1 = new List<Segment>();
-                List<Segment> SegmentList2 = new List<Segment>();
-                GetSegment(points1, SegmentClrList1, ref SegmentList1);
-                GetSegment(points2, SegmentClrList2, ref SegmentList2);
+                    //处理Segment
+                    List<COTSSegmentClr> SegmentClrList1 = new List<COTSSegmentClr>();
+                    List<COTSSegmentClr> SegmentClrList2 = new List<COTSSegmentClr>();
+                    List<Segment> SegmentList1 = new List<Segment>();
+                    List<Segment> SegmentList2 = new List<Segment>();
+                    GetSegment(points1, SegmentClrList1, ref SegmentList1);
+                    GetSegment(points2, SegmentClrList2, ref SegmentList2);
+
+                    //颗粒一
+                    Cv2.Threshold(mat, mat, 0, 0, ThresholdTypes.Binary);
+                    foreach (Segment segment in SegmentList1)
+                    {
+                        Cv2.Line(mat, new OpenCvSharp.Point(segment.Start, segment.Height), new OpenCvSharp.Point(segment.Start + segment.Length, segment.Height), Scalar.White, 1, LineTypes.AntiAlias);
+                    }
+                    Cv2.ConnectedComponentsWithStats(mat, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
 
-                CImageHandler m_ImagePro = new CImageHandler();
-                COTSParticleClr part1 = new COTSParticleClr();
-                part1.SetArea(stats.At<int>(1, 4) * dPixelSize * dPixelSize);
-                part1.SetParticleRect(new Rectangle(stats.At<int>(1, 0), stats.At<int>(1, 1), stats.At<int>(1, 2), stats.At<int>(1, 3)));
-                part1.GetFeature().SetSegmentsList(SegmentClrList1, false);
-                m_ImagePro.CalParticleImageProp(part1, dPixelSize);
-                COTSParticleClr part2 = new COTSParticleClr();
-                part2.SetArea(stats.At<int>(2, 4) * dPixelSize * dPixelSize);
-                part2.SetParticleRect(new Rectangle(stats.At<int>(2, 0), stats.At<int>(2, 1), stats.At<int>(2, 2), stats.At<int>(2, 3)));
-                part2.GetFeature().SetSegmentsList(SegmentClrList2, false);
-                m_ImagePro.CalParticleImageProp(part2, dPixelSize);
-
-                particle1.SegmentList = SegmentList1;
-                particle1.SegmentNum = SegmentList1.Count;
-                particle1.AveGray = (int)aveGray1.Average();
-                particle1.RectLeft = stats.At<int>(1, 0);
-                particle1.RectTop = stats.At<int>(1, 1);
-                particle1.RectWidth = stats.At<int>(1, 2);
-                particle1.RectHeight = stats.At<int>(1, 3);
-                particle1.Area = stats.At<int>(1, 4) * dPixelSize * dPixelSize;
-                particle1.PosX = (int)centroids.At<double>(1, 0);
-                particle1.PosY = (int)centroids.At<double>(1, 1);
-                particle1.DFERET = part1.GetFeretDiameter();
-                particle1.DMAX = part1.GetDMAX();
-                particle1.DMIN = part1.GetDMIN();
-                particle1.DPERP = part1.GetDMPERP();
-                particle1.PERIMETER = part1.GetDPRIMETER();
-                particle1.ORIENTATION = part1.GetORIENTATION();
-                particle1.DINSCR = part1.GetDINSCR();
-                particle1.DMEAN = part1.GetDMEAN();
-                particle1.DELONG = part1.GetDELONG();
-
-                particle2.SegmentList = SegmentList2;
-                particle2.SegmentNum = SegmentList2.Count;
-                particle2.AveGray = (int)aveGray2.Average();
-                particle2.RectLeft = stats.At<int>(2, 0);
-                particle2.RectTop = stats.At<int>(2, 1);
-                particle2.RectWidth = stats.At<int>(2, 2);
-                particle2.RectHeight = stats.At<int>(2, 3);
-                particle2.Area = stats.At<int>(2, 4) * dPixelSize * dPixelSize;
-                particle2.PosX = (int)centroids.At<double>(2, 0);
-                particle2.PosY = (int)centroids.At<double>(2, 1);
-                particle2.DFERET = part2.GetFeretDiameter();
-                particle2.DMAX = part2.GetDMAX();
-                particle2.DMIN = part2.GetDMIN();
-                particle2.DPERP = part2.GetDMPERP();
-                particle2.PERIMETER = part2.GetDPRIMETER();
-                particle2.ORIENTATION = part2.GetORIENTATION();
-                particle2.DINSCR = part2.GetDINSCR();
-                particle2.DMEAN = part2.GetDMEAN();
-                particle2.DELONG = part2.GetDELONG();
-
-                if (!SaveToDb(particle1, particle2))
-                {
-                    log.Trace("(GetSplitPartFun) SaveToDb Faild");
-                    return false;
+                    CopyToPart(particle1, SegmentList1, SegmentClrList1, aveGray1, stats, centroids, dPixelSize);
+
+                    //颗粒二
+                    Cv2.Threshold(mat, mat, 0, 0, ThresholdTypes.Binary);
+                    foreach (Segment segment in SegmentList2)
+                    {
+                        Cv2.Line(mat, new OpenCvSharp.Point(segment.Start, segment.Height), new OpenCvSharp.Point(segment.Start + segment.Length, segment.Height), Scalar.White, 1, LineTypes.AntiAlias);
+                    }
+                    Cv2.ConnectedComponentsWithStats(mat, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
+
+                    CopyToPart(particle2, SegmentList2, SegmentClrList2, aveGray2, stats, centroids, dPixelSize);
+
+                    if (!SaveToDb(particle1, particle2))
+                    {
+                        log.Trace("(GetSplitPartFun) SaveToDb Faild");
+                        return false;
+                    }
                 }
 
                 return true;
@@ -825,6 +797,47 @@ namespace OTSIncAReportGraph.OTSIncAReportGraphFuncation
                 return false;
             }
         }
+
+        /// <summary>
+        /// 拷贝颗粒数据
+        /// </summary>
+        /// <param name="particle"></param>
+        /// <param name="segments"></param>
+        /// <param name="SegmentClrList"></param>
+        /// <param name="aveGray"></param>
+        /// <param name="stats"></param>
+        /// <param name="centroids"></param>
+        /// <param name="dPixelSize"></param>
+        private void CopyToPart(Particle particle, List<Segment> segments, List<COTSSegmentClr> SegmentClrList, List<int> aveGray, Mat stats, Mat centroids, double dPixelSize)
+        {
+            CImageHandler m_ImagePro = new CImageHandler();
+            COTSParticleClr part = new COTSParticleClr();
+            part.SetArea(stats.At<int>(1, 4) * dPixelSize * dPixelSize);
+            part.SetParticleRect(new Rectangle(stats.At<int>(1, 0), stats.At<int>(1, 1), stats.At<int>(1, 2), stats.At<int>(1, 3)));
+            part.GetFeature().SetSegmentsList(SegmentClrList, false);
+            m_ImagePro.CalParticleImageProp(part, dPixelSize);
+
+            particle.SegmentList = segments;
+            particle.SegmentNum = segments.Count;
+            particle.AveGray = (int)aveGray.Average();
+            particle.RectLeft = stats.At<int>(1, 0);
+            particle.RectTop = stats.At<int>(1, 1);
+            particle.RectWidth = stats.At<int>(1, 2);
+            particle.RectHeight = stats.At<int>(1, 3);
+            particle.Area = stats.At<int>(1, 4) * dPixelSize * dPixelSize;
+            particle.PosX = (int)centroids.At<double>(1, 0);
+            particle.PosY = (int)centroids.At<double>(1, 1);
+            particle.DFERET = part.GetFeretDiameter();
+            particle.DMAX = part.GetDMAX();
+            particle.DMIN = part.GetDMIN();
+            particle.DPERP = part.GetDMPERP();
+            particle.PERIMETER = part.GetDPRIMETER();
+            particle.ORIENTATION = part.GetORIENTATION();
+            particle.DINSCR = part.GetDINSCR();
+            particle.DMEAN = part.GetDMEAN();
+            particle.DELONG = part.GetDELONG();
+        }
+
         /// <summary>
         /// 保存数据库
         /// </summary>