Browse Source

optimize the algorithm of removing duplicate particles

GSP 1 tháng trước cách đây
mục cha
commit
c715e3dcc9

+ 17 - 12
OTSIncAMeasureApp/0-OTSModel/OTSDataType/COTSField.cs

@@ -183,14 +183,14 @@ namespace OTSDataType
         {
             return m_pBSEImg;
         }
-        public Bitmap GetAnalysisParticleBlackColoredImage()
+        public Bitmap GetAnalysisParticleRandomColoredImage()
         {
             CImageHandler imghandler = new CImageHandler();
             List<COTSParticleClr> Parts = GetInitialParticles();
             Bitmap img = new Bitmap(this.ImgWidth, this.ImgHeight);
             var imgparam = m_sample.GetMsrParams().GetImageProcessParam();
             var pixelsize = m_sample.CalculatePixelSize();
-            imghandler.GetImageWithBlackColoredParts(Parts,imgparam,pixelsize, ref img);
+            imghandler.GetImageWithRandomColoredParts(Parts,imgparam,pixelsize, ref img);
             return img;
         }
         public Bitmap GetAnalysisParticleSTDColoredImage()
@@ -456,6 +456,7 @@ namespace OTSDataType
             List<COTSParticleClr> duplicateparts = new List<COTSParticleClr>();
             //find left side duplicate particles
             var leftparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap);
+            log.Info("leftparts:"+leftparts.Count);
             if (leftField != null && leftField.measureSequence < this.measureSequence)
             {
                 var rightsideparts = leftField.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap);
@@ -506,6 +507,7 @@ namespace OTSDataType
 
             //find up side duplicate particles
             var upparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.UP, overlap);
+            log.Info("upparts:" + upparts.Count);
             if (upField != null && upField.measureSequence < this.measureSequence)
             {
 
@@ -552,6 +554,7 @@ namespace OTSDataType
 
             //find right side duplicate particles
             var rightparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap);
+            log.Info("rightparts:" + rightparts.Count);
             if (rightField != null && rightField.measureSequence < this.measureSequence)
             {
                 log.Info("right side particles num:" + rightparts.Count.ToString());
@@ -602,6 +605,7 @@ namespace OTSDataType
 
             //find down side duplicate particles
             var downparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.DOWN, overlap);
+            log.Info("downparts:" + downparts.Count);
             if (downField != null && downField.measureSequence < this.measureSequence)
             {
 
@@ -639,6 +643,7 @@ namespace OTSDataType
                 }
             }
 
+            log.Info("duplicateparts number:" + duplicateparts.Count);
 
             foreach (var p in leftparts)
             {
@@ -685,15 +690,15 @@ namespace OTSDataType
                 }
             }
 
-
-            foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.CENTER, overlap))
+            var centerparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.CENTER, overlap);
+            foreach (var p in centerparts)
             {
                 if (!finalparts.Contains(p))
                 {
                     finalparts.Add(p);
                 }
             }
-
+            log.Info("centerparticles:" + centerparts.Count);
             this.SetListAnalysisParticles(finalparts);
             log.Info("removing duplicate particles result:" + finalparts.Count);
         }
@@ -701,14 +706,14 @@ namespace OTSDataType
         {
              sim = p.CalculateSimilarity(p1);
             double d = Math.Sqrt(Math.Pow(pCenter.X - p1Center.X, 2) + Math.Pow(pCenter.Y - p1Center.Y, 2));
-            double d1 = p.GetFeretDiameter() / 2;
+            double d1 = p.GetFeretDiameter()/ 2;
             double d2 = p1.GetFeretDiameter() / 2;
             if (d <= (d1 + d2) && sim > 0.90)
             {
 
                 return true;
             }
-            else if (d > (d1 + d2) && sim > 0.97)
+            else if (d > (d1 + d2) && sim > 0.98)
             {
                 return true;
             }
@@ -728,7 +733,7 @@ namespace OTSDataType
 
                     if (Math.Abs(right - this.GetOTSRect().GetTopLeft().X) < 2 * overlap)
                     {
-                        if (!borderedparts.Contains(p) || Math.Abs(left - right) > 2 * overlap)//not on the border or it's a big particle
+                        if (!borderedparts.Contains(p) /*|| Math.Abs(left - right) > 2 * overlap*/)//not on the border or it's a big particle
                         {
                             sideparts.Add(p);
                         }
@@ -747,7 +752,7 @@ namespace OTSDataType
                     p.GetOTSRect(ref left, ref top, ref right, ref bottom);
                     if (Math.Abs(this.GetOTSRect().GetBottomRight().X - left) < 2 * overlap)
                     {
-                        if (!borderedparts.Contains(p) || Math.Abs(left - right) > 2 * overlap)//not on the border or is a big part
+                        if (!borderedparts.Contains(p) /*|| Math.Abs(left - right) > 2 * overlap*/)//not on the border or is a big part
                         {
                             sideparts.Add(p);
                         }
@@ -765,7 +770,7 @@ namespace OTSDataType
                     p.GetOTSRect(ref left, ref top, ref right, ref bottom);
                     if (Math.Abs(this.GetOTSRect().GetTopLeft().Y - bottom) < 2 * overlap)
                     {
-                        if (!borderedparts.Contains(p) || Math.Abs(top - bottom) > 2 * overlap)//not on the border
+                        if (!borderedparts.Contains(p) /*|| Math.Abs(top - bottom) > 2 * overlap*/)//not on the border
                         {
                             sideparts.Add(p);
                         }
@@ -783,7 +788,7 @@ namespace OTSDataType
                     p.GetOTSRect(ref left, ref top, ref right, ref bottom);
                     if (Math.Abs(top - this.GetOTSRect().GetBottomRight().Y) < 2 * overlap)
                     {
-                        if (!borderedparts.Contains(p) || Math.Abs(top - bottom) > 2 * overlap)//not on the border
+                        if (!borderedparts.Contains(p) /*|| Math.Abs(top - bottom) > 2 * overlap*/)//not on the border
                         {
                             sideparts.Add(p);
                         }
@@ -803,7 +808,7 @@ namespace OTSDataType
                     int fldright = (int)fldrec.GetBottomRight().X;
                     int fldtop = (int)fldrec.GetTopLeft().Y;
                     int fldbottom = (int)fldrec.GetBottomRight().Y;
-                    if ((Math.Abs(top - fldtop) > 2 * overlap) && (Math.Abs(fldbottom - bottom) > 2 * overlap) && (Math.Abs(left - fldleft) > 2 * overlap) && (Math.Abs(fldright - right) > 2 * overlap))
+                    if ((Math.Abs(bottom - fldtop) >= 2*overlap) && (Math.Abs(top-fldbottom) >=2* overlap) && (Math.Abs(right - fldleft) >=  2*overlap) && (Math.Abs(left-fldright ) >= 2* overlap))
                     {
                         sideparts.Add(p);
                     }

+ 1 - 1
OTSIncAMeasureApp/1-OTSMeasure/Measure/3-MeasureFlow/ST_MSTMsg.cs

@@ -215,7 +215,7 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
         internal void InitFieldBSEAnalysisPartsDataMsg()
         {
             var poiFieldCentre = m_curFld.GetOTSPosition();
-            var pImg = m_curFld.GetAnalysisParticleBlackColoredImage();
+            var pImg = m_curFld.GetAnalysisParticleRandomColoredImage();
             this.iMsgType = ENUM_MSG_TYPE.MSAMPLERESULT;
             this.STMSampleRetData.iRetDataType = MSAMPLE_RET.REMOVEBG_DATA;
             this.STMSampleRetData.BSEData.pos.X = (int)poiFieldCentre.X;

+ 1 - 1
OTSIncAMeasureApp/ServiceCenter/CImageHandler.cs

@@ -426,7 +426,7 @@ namespace OTSModelSharp.ServiceCenter
 
             return;
         }
-        public void GetImageWithBlackColoredParts(List<COTSParticleClr> analysitParts, COTSImageProcParam a_pImgProcessParam, double a_pixelSize, ref Bitmap a_pBmpOut)
+        public void GetImageWithRandomColoredParts(List<COTSParticleClr> analysitParts, COTSImageProcParam a_pImgProcessParam, double a_pixelSize, ref Bitmap a_pBmpOut)
         {