Pārlūkot izejas kodu

improve the using method of the opencv connectedComponentsWithStats algorithm

gsp 3 gadi atpakaļ
vecāks
revīzija
862d58a8e1

BIN
Bin/x64/Debug/Config/Simulate/SimImage.bmp


+ 9 - 2
OTSCPP/OTSClrInterface/ImageProClr/ImageProForClr.h

@@ -17,10 +17,10 @@ namespace OTSCLRINTERFACE
 			return ret;
 
 		}
-		  bool GetParticlesBySpecialPartGrayRange(CBSEImgClr^ bseImg, CIntRangeClr^ perameter, COTSFieldDataClr^ fieldData)
+		  bool GetParticlesBySpecialPartGrayRange(CBSEImgClr^ bseImg, CIntRangeClr^ grayRange, CIntRangeClr^ diameterRange,double a_PixelSize, COTSFieldDataClr^ fieldData)
 		  {
 
-			  bool ret = COTSImageProcess::GetParticlesBySpecialGrayRange(bseImg->GetBSEImgPtr(), perameter->GetCIntRangePtr(), fieldData->GetOTSFieldDataPtr());
+			  bool ret = COTSImageProcess::GetParticlesBySpecialGrayRange(bseImg->GetBSEImgPtr(), grayRange->GetCIntRangePtr(),diameterRange->GetCIntRangePtr(), a_PixelSize,fieldData->GetOTSFieldDataPtr());
 			  return ret;
 
 		  }
@@ -58,6 +58,13 @@ namespace OTSCLRINTERFACE
 			 foundedPixelNum = num;
 			return ;
 		  }
+		  void GetSpecialGrayRangeImage(CBSEImgClr^ a_pImgIn, CIntRangeClr^ a_SpecialGrayRange, CBSEImgClr^ a_pBinImgOut, long% foundedPixelNum)
+		  {
+		  
+			  long num = 0;
+			  COTSImageProcess::GetSpecialGrayRangeImage(a_pImgIn->GetBSEImgPtr(), a_SpecialGrayRange->GetCIntRangePtr(), a_pBinImgOut->GetBSEImgPtr(), num);
+			  foundedPixelNum = num;
+		  }
 	};
 
 }

+ 149 - 95
OTSCPP/OTSImagePro/OTSImageProcess.cpp

@@ -1312,9 +1312,9 @@ namespace OTSIMGPROC
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
 			//Mat blurImg;
 			//medianBlur(cvcopyImg, blurImg, 5);//get rid of the noise point.
-			
-			Mat labels, stats, centroids;
-			int number = connectedComponentsWithStats(cvcopyImg, labels, stats, centroids, 8, CV_16U);
+			Mat labels = Mat::zeros(cvcopyImg.size(), CV_32S);
+			Mat  stats, centroids;
+			int number = connectedComponentsWithStats(cvcopyImg, labels, stats, centroids, 8, CV_32S);
 			
 			double rMin = a_pImageProcessParam->GetIncArea().GetStart()/2.0;
 			double rMax = a_pImageProcessParam->GetIncArea().GetEnd()/2.0;
@@ -1341,31 +1341,55 @@ namespace OTSIMGPROC
 				 
 				
 					Rect rectMax = Rect(x, y, w, h);
+					
+				
+					
 					Mat  rectROI = labels(rectMax).clone();
-					Mat imageROI = cvcopyImg(rectMax).clone();
+					Mat imageROI = Mat::zeros(rectMax.size(), cvcopyImg.type());
 
 					//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++)
+					int label = i;
+					for (int row = 0; row < rectROI.rows; row++)
 					{
-						for (int nY = 0; nY < rectROI.cols; nY++)
+						for (int col = 0; col < rectROI.cols; col++)
 						{
-							int v = rectROI.data[nX, nY];
-						
-							if (v == curlabel)
+							int v = rectROI.at<int>(row, col);
+
+							if (v == label)
 							{
-								imageROI.data[nX, nY] = 255;
+								imageROI.at<uchar>(row, col) = 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.
+								imageROI.at<uchar>(row, col) = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
 							}
 
 						}
 
 					}
-
+					//COTSParticleList listParticleInROI;
 					GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, imageROI.data, listParticleOut);
+
+					//if (listParticleInROI.size() >= 1)
+					//{
+					//	
+					//	//find the biggest particle in this group.
+					//	COTSParticlePtr bigP = listParticleInROI[0];
+					//	for (auto p : listParticleInROI)
+					//	{
+					//		//double partArea = p->GetArea()* a_pixelSize* a_pixelSize;
+					//		if (p->GetArea() > bigP->GetArea())
+					//		{
+					//			bigP = p;
+					//		}
+					//		/*if (partArea >= partAreaMin && partArea < partAreaMax)
+					//		{
+					//			listParticleOut.push_back(p);
+					//		}*/
+					//	}
+					//	listParticleOut.push_back(bigP);
+
+					//}
 				  
 				  }
 
@@ -1403,7 +1427,7 @@ namespace OTSIMGPROC
 				}
 				BYTE nAveGray = (BYTE)(nPixelAll / nPixelNum);
 				pParticle->SetAveGray(nAveGray);
-				pParticle->SetArea(nPixelNum);
+			
 
 
 			}
@@ -1416,7 +1440,7 @@ namespace OTSIMGPROC
 
 		return TRUE;
 	}
-	BOOL COTSImageProcess::GetParticlesBySpecialGrayRange(CBSEImgPtr a_pBSEImg, CIntRangePtr a_grayRange, COTSFieldDataPtr m_pFieldData)
+	BOOL COTSImageProcess::GetParticlesBySpecialGrayRange(CBSEImgPtr a_pBSEImg, CIntRangePtr a_grayRange,CIntRangePtr a_diameterRange,double a_pixelSize, COTSFieldDataPtr m_pFieldData)
 	{
 		ASSERT(m_pFieldData);
 
@@ -1465,14 +1489,16 @@ namespace OTSIMGPROC
 
 
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
-			//Mat blurImg;
-			//medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
-
-
-			Mat labels, stats, centroids;
-			int number = connectedComponentsWithStats(cvcopyImg, labels, stats, centroids, 8, CV_16U);
+		
 
+			Mat labels = Mat::zeros(cvcopyImg.size(), CV_32S);
+			Mat  stats, centroids;
+			int number = connectedComponentsWithStats(cvcopyImg, labels, stats, centroids, 8, CV_32S);
 
+			double rStart = a_diameterRange->GetStart() / 2.0;
+			double rEnd = a_diameterRange->GetEnd() / 2.0;
+			double areaStart = rStart * rStart * 3.14159;
+			double areaEnd = rEnd * rEnd * 3.14159;
 
 			COTSParticleList listParticleOut;
 			for (size_t i = 1; i < number; i++)
@@ -1486,99 +1512,111 @@ namespace OTSIMGPROC
 				int h = stats.at<int>(i, CC_STAT_HEIGHT);
 				int area = stats.at<int>(i, CC_STAT_AREA);
 
+				double actualArea = area * a_pixelSize * a_pixelSize;
 
+				
 
-				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++)
+				if (actualArea >= areaStart && actualArea < areaEnd)
 				{
-					for (int nY = 0; nY < rectROI.cols; nY++)
-					{
-						int v = rectROI.data[nX, nY];
+					Rect rectMax = Rect(x, y, w, h);
+				
+				
 
-						if (v == label)
-						{
-							imageROI.data[nX, nY] = 255;
-						}
-						else
+					Mat  rectROI = labels(rectMax).clone();
+					Mat imageROI = Mat::zeros(rectMax.size(), cvcopyImg.type());
+
+					//exclude the point which  intersect into this bounding box but is not in this group.
+					int label = i;
+					for (int row = 0; row < rectROI.rows; row++)
+					{
+						for (int col = 0; col < rectROI.cols; col++)
 						{
-							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.
+							int v = rectROI.at<int>(row, col);
+
+							if (v == label)
+							{
+								imageROI.at<uchar>(row, col) = 255;
+							}
+							else
+							{
+								imageROI.at<uchar>(row, col) = 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, imageROI.data, listParticleOut);
+
+		
+					//COTSParticleList listParticleInROI;
+					GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, imageROI.data, listParticleOut);//We will find more than one particle in one ROI. and We cann't decide which are the valid and not valid.So we will do another filter again later.
+					//if (listParticleInROI.size() >= 1)
+					//{
+					//	//find the biggest particle in this group.
+					//	COTSParticlePtr bigP = listParticleInROI[0];
+					//	for (auto p : listParticleInROI)
+					//	{
+					//		if (p->GetArea() > bigP->GetArea())
+					//		{
+					//			bigP = p;
+					//		}
+					//	}
+					//	listParticleOut.push_back(bigP);
+
+					//}
+				}
+				
 
 			}
 
 
 
 			// form a image only have particles on
-			COTSSegmentsList listImage;
+			//COTSSegmentsList listImage;
+			COTSParticleList listParticleOut2;
 			for (auto pParticle : listParticleOut)
 			{
-				COTSFeaturePtr pFeature = pParticle->GetFeature();
-				COTSSegmentsList listSegment = pFeature->GetSegmentsList();
-
-				long nPixelNum = 0;
-				long nPixelAll = 0;
-				int nStartS = 0;
-				int nHeightS = 0;
-				int nLengthS = 0;
-				for (auto pSegment : listSegment)
+				int area = pParticle->GetArea();
+				double pActualArea = area * a_pixelSize * a_pixelSize;
+				if (pActualArea >= areaStart && pActualArea < areaEnd)// do the second filter to remove invalid particles.
 				{
-					// update image list
-					COTSSegmentPtr pSegNew = COTSSegmentPtr(new COTSSegment(*pSegment.get()));
-					listImage.push_back(pSegNew);
+					COTSFeaturePtr pFeature = pParticle->GetFeature();
+					COTSSegmentsList listSegment = pFeature->GetSegmentsList();
 
+					long nPixelNum = 0;
+					long nPixelAll = 0;
+					int nStartS = 0;
+					int nHeightS = 0;
+					int nLengthS = 0;
+					for (auto pSegment : listSegment)
+					{
 
-					// get particle average gray
-					nStartS = pSegment->GetStart();
-					nHeightS = pSegment->GetHeight();
-					nLengthS = pSegment->GetLength();
-					nPixelNum += (long)nLengthS;
+						// get particle average gray
+						nStartS = pSegment->GetStart();
+						nHeightS = pSegment->GetHeight();
+						nLengthS = pSegment->GetLength();
+						nPixelNum += (long)nLengthS;
 
 
-					if (nHeightS > nHeightImg)
-					{
-						//LogErrorTrace(__FILE__, __LINE__, _T("seg height is wrong."));
-						return FALSE;
-					}
-					if ((nStartS + nLengthS - 1) > nWidthImg)
-					{
-						//LogErrorTrace(__FILE__, __LINE__, _T("seg starst and length is wrong."));
-						return FALSE;
-					}
-
-					for (unsigned int i = 0; i < nLengthS; i++)
-					{
-						if ((nStartS + i) > nWidthImg)
-						{
-							//LogErrorTrace(__FILE__, __LINE__, _T("seg start is wrong."));
-							return FALSE;
-						}
-						else if (nHeightS > nHeightImg)
+						for (unsigned int i = 0; i < nLengthS; i++)
 						{
-							//LogErrorTrace(__FILE__, __LINE__, _T("seg height is wrong."));
-							return FALSE;
-						}
 
-						long nValueTemp = (long)*(pSrcImg + nHeightS * nWidthImg + nStartS + i);
-						nPixelAll += nValueTemp;
+
+							long nValueTemp = (long)*(pSrcImg + nHeightS * nWidthImg + nStartS + i);
+							nPixelAll += nValueTemp;
+						}
 					}
+					BYTE nAveGray = (BYTE)(nPixelAll / nPixelNum);
+					pParticle->SetAveGray(nAveGray);
+
+					listParticleOut2.push_back(pParticle);
 				}
-				BYTE nAveGray = (BYTE)(nPixelAll / nPixelNum);
-				pParticle->SetAveGray(nAveGray);
-				pParticle->SetArea(nPixelNum);
+				
+				
 
 			}
-			m_pFieldData->SetParticleList(listParticleOut);
+			m_pFieldData->SetParticleList(listParticleOut2);
 		}
 
 
@@ -1714,9 +1752,10 @@ 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, 3);
-			pPixel = cvcopyImg.data;
+
+			//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, 3);
+			//pPixel = cvcopyImg.data;
 		a_pBinImgOut->SetImageData(pPixel, nWidthImg, nHeightImg);
 
 		foundedPixelNum = nNumParticle;
@@ -1774,11 +1813,11 @@ namespace OTSIMGPROC
 					pPixel[i] = 0;
 				}
 			}
-			COTSImageProcess::BErode3(pPixel, pTempImg, 3, nHeightImg, nWidthImg);
-			COTSImageProcess::BDilate3(pTempImg, pPixel, 3, 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;
+			//COTSImageProcess::BErode3(pPixel, pTempImg, 3, nHeightImg, nWidthImg);
+			//COTSImageProcess::BDilate3(pTempImg, pPixel, 3, 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;
 
 			
 		}
@@ -1838,11 +1877,11 @@ namespace OTSIMGPROC
 			default:
 				break;
 			}
-			COTSImageProcess::BErode3(pPixel, pTempImg, 3, nHeightImg, nWidthImg);
+			/*COTSImageProcess::BErode3(pPixel, pTempImg, 3, nHeightImg, nWidthImg);
 			COTSImageProcess::BDilate3(pTempImg, pPixel, 3, nHeightImg, nWidthImg);
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
 			medianBlur(cvcopyImg, cvcopyImg, 5);
-			pPixel = cvcopyImg.data;
+			pPixel = cvcopyImg.data;*/
 		}
 		a_pBinImgOut->SetImageData(pPixel,nWidthImg,nHeightImg);
 		
@@ -2079,6 +2118,21 @@ namespace OTSIMGPROC
 			{
 				return FALSE;
 			}
+		
+			COTSSegmentsList listSegment = pFeature->GetSegmentsList();
+
+			long nPixelNum = 0;
+
+			int nLengthS = 0;
+			for (auto pSegment : listSegment)
+			{
+
+				nLengthS = pSegment->GetLength();
+				nPixelNum += (long)nLengthS;
+
+			}
+			
+			pParticle->SetArea(nPixelNum);
 			a_listParticle.push_back(pParticle);
 		}
 

+ 1 - 1
OTSCPP/OTSImagePro/OTSImageProcess.h

@@ -65,7 +65,7 @@ namespace OTSIMGPROC {
 
 		static BOOL RemoveBGByFindContour(CBSEImgPtr m_pBSEImg, COTSImageProcessParamPtr a_pImageProcessParam, COTSFieldDataPtr m_pFieldData);
 		static BOOL RemoveBGByCVconnectivities(CBSEImgPtr m_pBSEImg, COTSImageProcessParamPtr a_pImageProcessParam, double a_pixelSize, COTSFieldDataPtr m_pFieldData);
-		static BOOL GetParticlesBySpecialGrayRange(CBSEImgPtr m_pBSEImg, CIntRangePtr a_grayRange, COTSFieldDataPtr m_pFieldData);
+		static BOOL GetParticlesBySpecialGrayRange(CBSEImgPtr m_pBSEImg, CIntRangePtr a_grayRange, CIntRangePtr a_diameterRange, double a_pixelSize, COTSFieldDataPtr m_pFieldData);
 
 		static CIntRangePtr CalBackground(CBSEImgPtr m_pBSEImg);
 		static void GetSpecialGrayRangeImage(CBSEImgPtr a_pImgIn, CIntRangePtr a_SpecialGrayRange, CBSEImgPtr a_pBinImgOut, long& foundedPixelNum);

+ 3 - 2
OTSIncAMeasureApp/0-OTSModel/Measure/1-OTSInclution/SmplMeasureInclution.cs

@@ -301,17 +301,18 @@ namespace OTSModelSharp
             CSampleParam pMsrParam = m_Sample.GetMsrParams();
             COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
             var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
+            var pixelsize = m_Sample.CalculatePixelSize();
             if (specialPartsparam.IsToRun)
             {
                 List<CSpecialGrayRange> ranges = pMsrParam.GetSpecialGrayRangeParam().GetIntRanges();
                 foreach (var grayRange in ranges)
                 {
                     CIntRangeClr range = new CIntRangeClr(grayRange.range.GetStart(), grayRange.range.GetEnd());
-                    curFldData.GetPartsBySpecialGray(range,grayRange.ifCollectXray);
+                    CIntRangeClr diaRange = new CIntRangeClr(grayRange.diameterRange.GetStart(), grayRange.diameterRange.GetEnd());
+                    curFldData.GetPartsBySpecialGray(range, diaRange,pixelsize,grayRange.ifCollectXray);
                 }
             }
 
-            var pixelsize = m_Sample.CalculatePixelSize();
             // remove BES image background
             curFldData.RemoveBSEImageBG(pImgProcessParam, pixelsize);
             

+ 14 - 14
OTSIncAMeasureApp/0-OTSModel/Measure/BSEPicData/COTSFieldData.cs

@@ -132,11 +132,11 @@ namespace OTSModelSharp
            
             return ;
         }
-        public void GetPartsBySpecialGray(CIntRangeClr range,bool ifXray)
+        public void GetPartsBySpecialGray(CIntRangeClr grayRange, CIntRangeClr diameterRange,double pixelSize, bool ifXray)
         {
             CImageHandler imghandler = new CImageHandler();
             List<COTSParticleClr> specialParts = new List<COTSParticleClr>();
-            imghandler.GetParticlesBySpecialGray(m_pBSEImg, range, ref specialParts);
+            imghandler.GetParticlesBySpecialGray(m_pBSEImg, grayRange,diameterRange,pixelSize, ref specialParts);
             foreach (var p in specialParts)
             {
                 m_listAllParticles.Add(p);
@@ -164,8 +164,8 @@ namespace OTSModelSharp
             m_listAnalysisParticles = new List<COTSParticleClr>();
             // get area range
             CDoubleRange oAreaRange = a_pImageProcessParam.GetIncAreaRange();
-            double rMin = oAreaRange.GetStart() / 2f;
-            double rMax = oAreaRange.GetEnd() / 2f;
+            double rMin = oAreaRange.GetStart() / 2.0;
+            double rMax = oAreaRange.GetEnd() / 2.0;
             double dAreaLow = rMin*rMin * 3.14159;
             double dAreaHigh = rMax*rMax * 3.14159;
     
@@ -179,34 +179,34 @@ namespace OTSModelSharp
             foreach (COTSParticleClr pParticle in m_listAllParticles)
             {
                
-                // get particle area 
+             
                 double dPartArea = pParticle.GetArea();
                 dPartArea = dPartArea * a_dPixelSize * a_dPixelSize;
                 pParticle.SetArea(dPartArea);
-                // get average gray level 
-                int nAveGrayLevel = pParticle.GetAveGray();
-            
             
-                // oversize particles
+                int nAveGrayLevel = pParticle.GetAveGray();
+
+
+
                 if (dPartArea > (double)dAreaHigh)
                 {
                     pParticle.SetType((int)otsdataconst.OTS_PARTCLE_TYPE.OVERSIZE);
                     overSizenum += 1;
                     continue;
                 }
-                // too small to measure
+
                 else if (dPartArea < (double)dAreaLow)
                 {
                     pParticle.SetType((int)otsdataconst.OTS_PARTCLE_TYPE.SMALL);
                     tooSmallnum += 1;
                     continue;
                 }
-                // set particle tag id
-               
+
+
                 pParticle.SetTagId(nTagId);//give all the conforming particles a unified sequence no.
-                // set field id
+              
                 pParticle.SetFieldId(GetId());
-                // add the particle into the output particles list
+              
                 pParticle.SetType((int)otsdataconst.OTS_PARTCLE_TYPE.NO_ANALYSIS_X_RAY);
                 pParticle.SetTypeName("Not Identified");
               

+ 20 - 8
OTSIncAMeasureApp/0-OTSModel/Measure/DBDataTransition/IncADataDB.cs

@@ -41,23 +41,35 @@ namespace OTSModelSharp
             
             return ret;
         }
-        public string GetUpdataAIncACmdStr(COTSParticleClr a_pParticle)
+        public KeyValuePair<string,SQLiteParameter[]> GetUpdataAIncACmd(COTSParticleClr a_pParticle)
         {
 
-            if (a_pParticle == null)
-            {
-                return "";
-            }
+            //if (a_pParticle == null)
+            //{
+            //    return "";
+            //}
 
 
 
             //var datastorePtr = GetDatastore();
 
-            string sSQLCommand = "Update IncAData set TypeId={0},TypeName= \'{1} \',TypeColor= \'{2} \' where FieldID = {3} and ParticleId = {4} ";  //sSQLCommand.Format(sSQLCommand,a_pParticle->GetAveGray(),a_pParticle->GetArea(),a_pParticle->GetType(),a_pParticle->GetFieldId(),a_pParticle->GetTagId());
-            sSQLCommand = string.Format(sSQLCommand,  a_pParticle.GetClassifyId(),a_pParticle.GetTypeName(),a_pParticle.GetTypeColor(), a_pParticle.GetFieldId(), a_pParticle.GetTagId());
+            string sSQLCommand = "Update IncAData set TypeId=@TypeId,TypeName= @TypeName,TypeColor=@TypeColor where FieldID =@FieldId and ParticleId =@ParticleId ";  //sSQLCommand.Format(sSQLCommand,a_pParticle->GetAveGray(),a_pParticle->GetArea(),a_pParticle->GetType(),a_pParticle->GetFieldId(),a_pParticle->GetTagId());
+            var paras = new SQLiteParameter[5];
+            paras[0] = new SQLiteParameter("TypeId");
+            paras[0].Value = a_pParticle.GetClassifyId();
+            paras[1] = new SQLiteParameter("TypeName");
+            paras[1].Value = a_pParticle.GetTypeName();
+            paras[2] = new SQLiteParameter("TypeColor");
+            paras[2].Value = a_pParticle.GetTypeColor();
+            paras[3] = new SQLiteParameter("FieldId");
+            paras[3].Value = a_pParticle.GetFieldId();
+            paras[4] = new SQLiteParameter("ParticleId");
+            paras[4].Value = a_pParticle.GetTagId();
+
+            //sSQLCommand = string.Format(sSQLCommand,  a_pParticle.GetClassifyId(),a_pParticle.GetTypeName(),a_pParticle.GetTypeColor(), a_pParticle.GetFieldId(), a_pParticle.GetTagId());
             
 
-            return sSQLCommand;
+            return new KeyValuePair<string, SQLiteParameter[]>(sSQLCommand,paras);
         }
 
         public bool SaveAIncA(COTSParticleClr a_pParticle,  System.Drawing.Point fldPos)

+ 3 - 3
OTSIncAMeasureApp/0-OTSModel/Measure/DBDataTransition/IncAFileMgr.cs

@@ -312,10 +312,10 @@ namespace OTSModelSharp
             List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
             foreach (var pParticle in m_listParticle)
             {
-               var str= IncADataDB.GetUpdataAIncACmdStr(pParticle);
-                cmdlist.Add(new KeyValuePair<string, SQLiteParameter[]>(str,null));
+               var str= IncADataDB.GetUpdataAIncACmd(pParticle);
+                cmdlist.Add(str);
             }
-            ExecuteNonQueryBatch(ref cmdlist);
+            dbStore.ExecuteNonQueryBatch(ref cmdlist);
             return ;
         }
         public void ExecuteNonQueryBatch(ref List<KeyValuePair<string, SQLiteParameter[]>> cmds)

+ 1 - 14
OTSIncAMeasureApp/0-OTSModel/Measure/ParamData/COTSMsrPrjResultData.cs

@@ -1439,20 +1439,7 @@ namespace OTSModelSharp
                 }
 
                 string filename = strFilePath + "\\" + spl.GetName() + "\\" + spl.GetName() + ".rst";
-                ////获取测量项目文件
-                //XmlDocument doc = new XmlDocument();
-                ////载入xml文件
-                //doc.Load(filename);
-
-                //pMsrParam.SetSTDName(stdFileName);
-                //XmlNode root = doc.SelectSingleNode("XMLData");
-                //root.RemoveAll();
-                //spl.Serialize(true, doc, root);
-
-
-
-                //string imgpath = filename;
-                //const string file = imgpath;
+               
                 XmlDocument doc=new XmlDocument();
                 doc.Load(filename);
 

+ 9 - 0
OTSIncAMeasureApp/0-OTSModel/Measure/ParamData/CSpecialGrayRangeParam.cs

@@ -13,21 +13,28 @@ namespace OTSMeasureApp._0_OTSModel.Measure.ParamData
   public  class CSpecialGrayRange:ISlo
     {
         public  CIntRange range=new CIntRange();
+        public CIntRange diameterRange = new CIntRange();
         public bool ifCollectXray;
      
         public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
         {
             xInt xStart = new xInt();
             xInt xEnd = new xInt();
+            xInt xdiaStart = new xInt();
+            xInt xdiaEnd = new xInt();
             xBool xIfXray = new xBool();
             Slo slo = new Slo();
             slo.Register("start", xStart);
             slo.Register("end", xEnd);
+            slo.Register("diameterStart", xdiaStart);
+            slo.Register("diameterEnd", xdiaEnd);
             slo.Register("collectXray", xIfXray);
             if (isStoring)
             {
                 xStart.AssignValue(range.GetStart());
                 xEnd.AssignValue(range.GetEnd());
+                xdiaStart.AssignValue(diameterRange.GetStart());
+                xdiaEnd.AssignValue(diameterRange.GetEnd());
                 xIfXray.AssignValue(ifCollectXray);
 
                 slo.Serialize(true, classDoc, rootNode);
@@ -37,6 +44,8 @@ namespace OTSMeasureApp._0_OTSModel.Measure.ParamData
                 slo.Serialize(false, classDoc, rootNode);
                 range.SetStart(xStart.value());
                 range.SetEnd(xEnd.value());
+                diameterRange.SetStart(xdiaStart.value());
+                diameterRange.SetEnd(xdiaEnd.value());
                 ifCollectXray = xIfXray.value();
 
             }

+ 12 - 0
OTSIncAMeasureApp/5-OTSMeasureStatuImageFun/OTSImageData.cs

@@ -183,6 +183,18 @@ namespace OTSMeasureApp
                 return false;
             }
         }
+        public bool GetSpecialGrayImage(byte[] cData, int cWidth, int cHeight, int startGray,int endGray, ref byte[] BSEImageNoBG)
+        {
+            try
+            {
+                var ImageFun = new OTSBSEImageFun();
+                return ImageFun.GetBSEImage(cData, cHeight, cWidth,startGray,endGray, ref BSEImageNoBG);
+            }
+            catch (Exception ex)
+            {
+                return false;
+            }
+        }
 
 
         #region 获取工作距离与放大倍数

+ 12 - 12
OTSIncAMeasureApp/5-OTSMeasureStatuImageFun/frmSpecialGrayParticle.cs

@@ -161,7 +161,7 @@ namespace OTSMeasureApp
 
         }
         #endregion
-        protected void ShowRemoveBGImage(COTSImageProcParam ImgProcPrm)
+        protected void ShowRemoveBGImage(int startGray,int endGray)
         {
             try
             {
@@ -177,7 +177,7 @@ namespace OTSMeasureApp
              
                  byte[] cBseData=new byte[m_iHeight*m_iWidth];
        
-              var  bfResult = m_ImageData.GetRemoveBGImage(ImgProcPrm, m_iWidth, m_iHeight, bBseData, ref cBseData);
+              var  bfResult = m_ImageData.GetSpecialGrayImage(bBseData,m_iWidth, m_iHeight, startGray,endGray, ref cBseData);
 
                 bBseData = cBseData;
                 //取图不成功就返回
@@ -292,17 +292,17 @@ namespace OTSMeasureApp
             COTSImageProcParam cOTSImgProc = new COTSImageProcParam();
 
             //remove the low end gray pixel
-            CIntRange cIntRange = new CIntRange();
-            cIntRange.SetStart(0);
-            cIntRange.SetEnd(BseGrayMinValue);
-            cOTSImgProc.SetBGGray(cIntRange);        
-            ShowRemoveBGImage(cOTSImgProc);
-
+            //CIntRange cIntRange = new CIntRange();
+            //cIntRange.SetStart(0);
+            //cIntRange.SetEnd(BseGrayMinValue);
+            //cOTSImgProc.SetBGGray(cIntRange);        
+          var reBseImg=  ShowRemoveBGImage(bBseData,BseGrayMinValue, bseGrayMaxValue);
+            ShowBSEImage(reBseImg);
             //remove the high end gray pixel
-            cIntRange.SetStart(BseGrayMaxValue);
-            cIntRange.SetEnd(255);
-            cOTSImgProc.SetBGGray(cIntRange);
-            ShowRemoveBGImage(cOTSImgProc);
+            //cIntRange.SetStart(BseGrayMaxValue);
+            //cIntRange.SetEnd(255);
+            //cOTSImgProc.SetBGGray(cIntRange);
+            //ShowRemoveBGImage(cOTSImgProc);
         }
 
         private void btnCancel_Click(object sender, EventArgs e)

+ 7 - 7
OTSIncAMeasureApp/ServiceCenter/CImageHandler.cs

@@ -72,14 +72,14 @@ namespace OTSModelSharp.ServiceInterface
 
 
 
-            COTSImageProcParam ImgProcPrm = new COTSImageProcParam();
-            CIntRange cIntRangeClr = new CIntRange();
+         
+            CIntRangeClr cIntRangeClr = new CIntRangeClr();
             cIntRangeClr.SetStart(grayStart);
             cIntRangeClr.SetEnd(grayEnd);
-            ImgProcPrm.SetBGGray(cIntRangeClr);
-
-            RemoveBackGround(pBSEImageIn, ImgProcPrm, ref pBSEImageOut);
           
+            OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();
+            int num=0;
+            imgpro.GetSpecialGrayRangeImage(pBSEImageIn, cIntRangeClr, pBSEImageOut,ref num);
 
             BSEImageNoBG = pBSEImageOut.GetImageDataPtr();
 
@@ -153,13 +153,13 @@ namespace OTSModelSharp.ServiceInterface
             return true;
 
         }
-        public bool GetParticlesBySpecialGray(CBSEImgClr img, CIntRangeClr range, ref List<COTSParticleClr> parts)
+        public bool GetParticlesBySpecialGray(CBSEImgClr img, CIntRangeClr grayrange, CIntRangeClr diameterRange,double a_pixelSize, ref List<COTSParticleClr> parts)
         {
             OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();
 
             //OTSCLRINTERFACE.COTSImgProcPrmClr prm = GetImageProcPrmClr(a_pImgProcessParam);
             OTSCLRINTERFACE.COTSFieldDataClr flddataclr = new OTSCLRINTERFACE.COTSFieldDataClr();
-            imgpro.GetParticlesBySpecialPartGrayRange(img, range, flddataclr);
+            imgpro.GetParticlesBySpecialPartGrayRange(img, grayrange,diameterRange,a_pixelSize, flddataclr);
 
             parts = flddataclr.GetParticleList();
             return true;

+ 4 - 1
OTSIncAMeasureApp/ServiceCenter/DTLBase/CSQLiteTable.cs

@@ -299,6 +299,9 @@ namespace OTSModelSharp.DTLBase
             return builder.ToString();
         }
 
-
+        public KeyValuePair<string, SQLiteParameter[]> GetUpdateCommand(List<int> a_updateColIndexes, int a_nConditionColIndex)
+        {
+            throw new NotImplementedException();
+        }
     }
 }

+ 2 - 0
OTSIncAMeasureApp/ServiceCenter/DTLBase/IDBTableBase.cs

@@ -33,5 +33,7 @@ namespace OTSModelSharp.DTLBase
          string GetInsertCommandFormatString(List<int> a_colIndexes);
 		 string GetUpdateCommandFormatString(List<int> a_updateColIndexes, int a_nConditionColIndex);
 
+        KeyValuePair<string, SQLiteParameter[]> GetUpdateCommand(List<int> a_updateColIndexes, int a_nConditionColIndex);
+
     }
 }