Jelajahi Sumber

optimizing the OpenCV connectivitie method to process the bse image.

gsp 3 tahun lalu
induk
melakukan
3f4d57de0b

+ 1 - 1
OTSCPP/OTSClrInterface/ImageProClr/ImageProForClr.h

@@ -13,7 +13,7 @@ namespace OTSCLRINTERFACE
 		  bool GetFieldDataFromImage(CBSEImgClr^ bseImg, COTSImgProcPrmClr^ perameter, COTSFieldDataClr^ fieldData)
 		{
 			 
-			bool ret = COTSImageProcess::RemoveBGByFindContour(bseImg->GetBSEImgPtr(), perameter->GetImgPrcPrmPtr(), fieldData->GetOTSFieldDataPtr());
+			bool ret = COTSImageProcess::RemoveBGByCVconnectivities(bseImg->GetBSEImgPtr(), perameter->GetImgPrcPrmPtr(), fieldData->GetOTSFieldDataPtr());
 			return ret;
 
 		}

+ 57 - 36
OTSCPP/OTSImagePro/OTSImageProcess.cpp

@@ -1030,7 +1030,6 @@ namespace OTSIMGPROC
 			m_pFieldData->SetParticleList(listParticleEmpty);
 		
 
-			//LogInfoTrace(__FILE__, __LINE__, _T("RemoveBSEImageBG: no particle is found."));
 		}
 		else
 		{
@@ -1038,13 +1037,11 @@ namespace OTSIMGPROC
 			
 
 			// get the area image
-			COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
-			COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
+			
 
 			Mat blurImg;
 			Mat srcImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
-			//Mat srcImg=Mat(nWidthImg,;
-			//srcImg.data = pPixel;
+			
 			medianBlur(srcImg, blurImg, 3);//smooth the edge
 
 
@@ -1183,7 +1180,7 @@ namespace OTSIMGPROC
 
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
 			Mat blurImg;
-			medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
+			medianBlur(cvcopyImg, blurImg, 5);//smooth the edge
 
 			vector<vector<Point>>contours;
 			
@@ -1340,15 +1337,12 @@ namespace OTSIMGPROC
 
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
 			Mat blurImg;
-			medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
-			/*imshow("blur", blurImg);
-			imshow("original", cvcopyImg);*/
+			medianBlur(cvcopyImg, blurImg, 5);//get rid of the noise point.
 			
-			//vector<vector<Point>>contours;
-			Mat out, stats, centroids;
-			int number = connectedComponentsWithStats(blurImg, out, stats, centroids, 8, CV_16U);
+			Mat labels, stats, centroids;
+			int number = connectedComponentsWithStats(blurImg, labels, stats, centroids, 8, CV_16U);
 			
-			//findContours(cvcopyImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
+		
 
 			COTSParticleList listParticleOut;
 			for (size_t i = 1; i < number; i++)
@@ -1363,31 +1357,33 @@ namespace OTSIMGPROC
 				  int area = stats.at<int>(i, CC_STAT_AREA);
 				
 
-				//Rect rectMax = boundingRect(contours[i]);
+				
 				  Rect rectMax = Rect(x, y, w, h);
-				Mat  rectROI = blurImg(rectMax).clone();
-
+				Mat  rectROI = labels(rectMax).clone();
+				Mat imageROI = blurImg(rectMax).clone();
 
-				//exclude the point which  intersect into this bounding box but is not in this contour.
+				//exclude the point which  intersect into this bounding box but is not in this group.
+				int curlabel = i;
 				for (int nX = 0; nX < rectROI.rows; nX++)
 				{
 					for (int nY = 0; nY < rectROI.cols; nY++)
 					{
 						int v = rectROI.data[nX, nY];
-						if (v == i)
+						
+						if (v == curlabel)
 						{
-							rectROI.data[nX, nY] = 1;
+							imageROI.data[nX, nY] = 255;
 						}
 						else
 						{
-							rectROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
+							imageROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
 						}
 
 					}
 
 				}
 
-				GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, rectROI.data, listParticleOut);
+				GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, imageROI.data, listParticleOut);
 
 			}
 
@@ -1501,8 +1497,7 @@ namespace OTSIMGPROC
 			listParticleEmpty.clear();
 			m_pFieldData->SetParticleList(listParticleEmpty);
 
-
-			//LogInfoTrace(__FILE__, __LINE__, _T("RemoveBSEImageBG: no particle is found."));
+		
 		}
 		else
 		{
@@ -1511,37 +1506,55 @@ namespace OTSIMGPROC
 
 
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
-			Mat blurImg;
-			medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
+			//Mat blurImg;
+			//medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
+
+
+			Mat labels, stats, centroids;
+			int number = connectedComponentsWithStats(cvcopyImg, labels, stats, centroids, 8, CV_16U);
+
 
-			vector<vector<Point>>contours;
-		/*	imshow("sss", blurImg);*/
-			findContours(blurImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
 
 			COTSParticleList listParticleOut;
-			for (size_t i = 0; i < contours.size(); i++)
+			for (size_t i = 1; i < number; i++)
 			{
+				int center_x = centroids.at<double>(i, 0);
+				int center_y = centroids.at<double>(i, 1);
+				//¾ØÐα߿ò
+				int x = stats.at<int>(i, CC_STAT_LEFT);
+				int y = stats.at<int>(i, CC_STAT_TOP);
+				int w = stats.at<int>(i, CC_STAT_WIDTH);
+				int h = stats.at<int>(i, CC_STAT_HEIGHT);
+				int area = stats.at<int>(i, CC_STAT_AREA);
 
-				Rect rectMax = boundingRect(contours[i]);
-				Mat  rectROI = cvcopyImg(rectMax).clone();
 
 
-				//exclude the point which  intersect into this bounding box but is not in this contour.
+				Rect rectMax = Rect(x, y, w, h);
+				Mat  rectROI = labels(rectMax).clone();
+				Mat imageROI = cvcopyImg(rectMax).clone();
+
+				//exclude the point which  intersect into this bounding box but is not in this group.
+				int label = i;
 				for (int nX = 0; nX < rectROI.rows; nX++)
 				{
 					for (int nY = 0; nY < rectROI.cols; nY++)
 					{
-						double localPos = pointPolygonTest(contours[i], Point2f(nX + rectMax.x, nY + rectMax.y), false);
-						if (localPos == -1)
+						int v = rectROI.data[nX, nY];
+
+						if (v == label)
 						{
-							rectROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
+							imageROI.data[nX, nY] = 255;
+						}
+						else
+						{
+							imageROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
 						}
 
 					}
 
 				}
 
-				GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, rectROI.data, listParticleOut);
+				GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, imageROI.data, listParticleOut);
 
 			}
 
@@ -1802,6 +1815,11 @@ namespace OTSIMGPROC
 			}
 			COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
 			COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
+			//Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);// use the medianblur method to achieve the same effect as open morphology(errod and dialate).
+			//medianBlur(cvcopyImg, cvcopyImg, 5);
+			//pPixel = cvcopyImg.data;
+
+			
 		}
 		else
 		{
@@ -1861,6 +1879,9 @@ namespace OTSIMGPROC
 			}
 			COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
 			COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
+			/*Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
+			medianBlur(cvcopyImg, cvcopyImg, 5);
+			pPixel = cvcopyImg.data;*/
 		}
 		a_pBinImgOut->SetImageData(pPixel,nWidthImg,nHeightImg);
 		

+ 32 - 12
OTSIncAMeasureApp/OTSIncAMeasureAppForm.Designer.cs

@@ -93,6 +93,7 @@
             this.dockPanel = new OTS.WinFormsUI.Docking.DockPanel();
             this.ribbonButton3 = new System.Windows.Forms.RibbonButton();
             this.ribbonButton1 = new System.Windows.Forms.RibbonButton();
+            this.ribbonOrbRecentItem1 = new System.Windows.Forms.RibbonOrbRecentItem();
             this.statusStrip1.SuspendLayout();
             this.SuspendLayout();
             // 
@@ -159,6 +160,7 @@
             this.rbMenu.BorderMode = System.Windows.Forms.RibbonWindowMode.InsideWindow;
             this.rbMenu.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F);
             this.rbMenu.Location = new System.Drawing.Point(0, 0);
+            this.rbMenu.Margin = new System.Windows.Forms.Padding(2);
             this.rbMenu.Minimized = true;
             this.rbMenu.Name = "rbMenu";
             // 
@@ -178,6 +180,7 @@
             this.rbMenu.OrbDropDown.MenuItems.Add(this.rbExitApp);
             this.rbMenu.OrbDropDown.Name = "";
             this.rbMenu.OrbDropDown.OptionItems.Add(this.rbSelectDlg);
+            this.rbMenu.OrbDropDown.RecentItems.Add(this.ribbonOrbRecentItem1);
             this.rbMenu.OrbDropDown.Size = new System.Drawing.Size(527, 430);
             this.rbMenu.OrbDropDown.TabIndex = 0;
             this.rbMenu.OrbImage = global::OTSMeasureApp.Properties.Resources.logo_40;
@@ -190,7 +193,7 @@
             this.rbMenu.QuickAcessToolbar.Image = null;
             this.rbMenu.QuickAcessToolbar.Tag = null;
             this.rbMenu.QuickAcessToolbar.ToolTipImage = null;
-            this.rbMenu.Size = new System.Drawing.Size(1924, 130);
+            this.rbMenu.Size = new System.Drawing.Size(1277, 130);
             this.rbMenu.TabIndex = 0;
             this.rbMenu.Tabs.Add(this.rbTabHome);
             this.rbMenu.Tabs.Add(this.rbTabView);
@@ -702,11 +705,11 @@
             this.TSGrayVal,
             this.STSemCoordinate,
             this.toolStripStatusLabel1});
-            this.statusStrip1.Location = new System.Drawing.Point(0, 1010);
+            this.statusStrip1.Location = new System.Drawing.Point(0, 671);
             this.statusStrip1.Name = "statusStrip1";
-            this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 14, 0);
+            this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 9, 0);
             this.statusStrip1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
-            this.statusStrip1.Size = new System.Drawing.Size(1924, 35);
+            this.statusStrip1.Size = new System.Drawing.Size(1277, 26);
             this.statusStrip1.TabIndex = 2;
             this.statusStrip1.Text = "statusStrip1";
             // 
@@ -714,20 +717,20 @@
             // 
             this.TSGrayVal.BorderSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Right;
             this.TSGrayVal.Name = "TSGrayVal";
-            this.TSGrayVal.Size = new System.Drawing.Size(68, 28);
+            this.TSGrayVal.Size = new System.Drawing.Size(48, 21);
             this.TSGrayVal.Text = "灰度值";
             // 
             // STSemCoordinate
             // 
             this.STSemCoordinate.BorderSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Right;
             this.STSemCoordinate.Name = "STSemCoordinate";
-            this.STSemCoordinate.Size = new System.Drawing.Size(88, 28);
+            this.STSemCoordinate.Size = new System.Drawing.Size(62, 21);
             this.STSemCoordinate.Text = "SEM坐标";
             // 
             // toolStripStatusLabel1
             // 
             this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
-            this.toolStripStatusLabel1.Size = new System.Drawing.Size(77, 28);
+            this.toolStripStatusLabel1.Size = new System.Drawing.Size(54, 21);
             this.toolStripStatusLabel1.Text = "IsReady";
             this.toolStripStatusLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
             this.toolStripStatusLabel1.Visible = false;
@@ -742,9 +745,9 @@
             this.dockPanel.DockLeftPortion = 0.21D;
             this.dockPanel.DockRightPortion = 0.27D;
             this.dockPanel.Location = new System.Drawing.Point(0, 130);
-            this.dockPanel.Margin = new System.Windows.Forms.Padding(6);
+            this.dockPanel.Margin = new System.Windows.Forms.Padding(4);
             this.dockPanel.Name = "dockPanel";
-            this.dockPanel.Size = new System.Drawing.Size(1924, 880);
+            this.dockPanel.Size = new System.Drawing.Size(1277, 541);
             dockPanelGradient1.EndColor = System.Drawing.SystemColors.ControlLight;
             dockPanelGradient1.StartColor = System.Drawing.SystemColors.ControlLight;
             autoHideStripSkin1.DockStripGradient = dockPanelGradient1;
@@ -819,11 +822,26 @@
             this.ribbonButton1.ToolTipImage = null;
             this.ribbonButton1.ToolTipTitle = null;
             // 
+            // ribbonOrbRecentItem1
+            // 
+            this.ribbonOrbRecentItem1.AltKey = null;
+            this.ribbonOrbRecentItem1.DropDownArrowDirection = System.Windows.Forms.RibbonArrowDirection.Down;
+            this.ribbonOrbRecentItem1.DropDownArrowSize = new System.Drawing.Size(5, 3);
+            this.ribbonOrbRecentItem1.Image = ((System.Drawing.Image)(resources.GetObject("ribbonOrbRecentItem1.Image")));
+            this.ribbonOrbRecentItem1.SmallImage = ((System.Drawing.Image)(resources.GetObject("ribbonOrbRecentItem1.SmallImage")));
+            this.ribbonOrbRecentItem1.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
+            this.ribbonOrbRecentItem1.Tag = null;
+            this.ribbonOrbRecentItem1.Text = "特殊颗粒识别设置";
+            this.ribbonOrbRecentItem1.ToolTip = null;
+            this.ribbonOrbRecentItem1.ToolTipImage = null;
+            this.ribbonOrbRecentItem1.ToolTipTitle = null;
+            this.ribbonOrbRecentItem1.Click += new System.EventHandler(this.ribbonOrbRecentItem1_Click);
+            // 
             // OTSIncAMeasureAppForm
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(1924, 1045);
+            this.ClientSize = new System.Drawing.Size(1277, 697);
             this.Controls.Add(this.dockPanel);
             this.Controls.Add(this.statusStrip1);
             this.Controls.Add(this.rbMenu);
@@ -831,7 +849,8 @@
             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
             this.IsMdiContainer = true;
             this.KeyPreview = true;
-            this.MinimumSize = new System.Drawing.Size(1015, 744);
+            this.Margin = new System.Windows.Forms.Padding(2);
+            this.MinimumSize = new System.Drawing.Size(682, 509);
             this.Name = "OTSIncAMeasureAppForm";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
             this.Text = "样品测量程序";
@@ -898,5 +917,6 @@
         public System.Windows.Forms.RibbonButton ribPolygon;
         public System.Windows.Forms.RibbonButton rbSTDEdit;
         public System.Windows.Forms.RibbonButton rbReClassify;
+        private System.Windows.Forms.RibbonOrbRecentItem ribbonOrbRecentItem1;
     }
 }

+ 7 - 2
OTSIncAMeasureApp/OTSIncAMeasureAppForm.cs

@@ -13,6 +13,7 @@ using OTSModelSharp.ResourceManage;
 using static OTSDataType.otsdataconst;
 using System.Diagnostics;
 using OTSModelSharp.ServiceInterface;
+using OTSMeasureApp._0_OTSModel.Measure.ParamData;
 
 namespace OTSMeasureApp 
 {
@@ -287,8 +288,7 @@ namespace OTSMeasureApp
         }
 
 
-        //OTSSolutionWindow 给 MeasureApp 发送样品checkbox发生变化事件
-        //string sSampleName : 样品名;  bool bCheckBoxStatu:  样品名对应的CheckBox发生变化的值(选中/不选中)
+   
         public void Rev_SoluWindowReqCheckBosStatuChange_Event(string sSampleName, bool bCheckBoxStatu)
         {
             string sWSampleName = m_ProjParam.GetWorkSampleName();
@@ -1219,5 +1219,10 @@ namespace OTSMeasureApp
             About m_about = new About();
             m_about.ShowDialog();
         }
+
+        private void ribbonOrbRecentItem1_Click(object sender, EventArgs e)
+        {
+            System.Diagnostics.Process.Start("notepad.exe", CSpecialGrayRangeParam.GetParamFileFullName());
+        }
     }
 }

+ 14 - 0
OTSIncAMeasureApp/OTSIncAMeasureAppForm.resx

@@ -152,6 +152,20 @@
     <value>
         iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAW
         JQAAFiUBSVIk8AAAABNJREFUOE9jGAWjYBSMAjBgYAAABBAAAadEfGMAAAAASUVORK5CYII=
+</value>
+  </data>
+  <data name="ribbonOrbRecentItem1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+        YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAaSURBVFhH7cEBAQAAAIIg/69uSEAAAADAuRoQIAABnXhJ
+        QwAAAABJRU5ErkJggg==
+</value>
+  </data>
+  <data name="ribbonOrbRecentItem1.SmallImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+        YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAATSURBVDhPYxgFo2AUjAIwYGAAAAQQAAGnRHxjAAAAAElF
+        TkSuQmCC
 </value>
   </data>
   <data name="ribCircle.SmallImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

+ 4 - 3
OTSIncAReportApp/1-UI/Control_Graph/Controls/Control_DrawDistrbutionImageAndBSE.cs

@@ -1032,7 +1032,7 @@ namespace OTSIncAReportGraph.Controls
                             {
                                 dp.IsMouseOver = true;
 
-
+                               
                                 //显示x-ray能谱图 
                                 if (control_XRayTable1.Visible == false)
                                     ShowXRay(dp);
@@ -1293,10 +1293,11 @@ namespace OTSIncAReportGraph.Controls
         /// <param name="in_dparticle"></param>
         private void ShowXRay(DisplayParticle in_dparticle)
         {
-            
+
+            m_mouseOver_dparticle = in_dparticle;//将显示xray的dparticle记录给全局变量
             if (delaytimer.Enabled == false)
             {
-                m_mouseOver_dparticle = in_dparticle;//将显示xray的dparticle记录给全局变量
+              
 
                 delaytimer.Tick += Delaytimer_Tick;
                 delaytimer.Interval = 500;