浏览代码

fix the remove background bug.

gsp 3 年之前
父节点
当前提交
937165284c
共有 2 个文件被更改,包括 27 次插入30 次删除
  1. 17 19
      OTSCPP/OTSImagePro/OTSImageProcess.cpp
  2. 10 11
      OTSIncAMeasureApp/0-OTSModel/OTSDataType/COTSSample.cs

+ 17 - 19
OTSCPP/OTSImagePro/OTSImageProcess.cpp

@@ -1177,8 +1177,7 @@ namespace OTSIMGPROC
 		{
 
 			// get the area image
-			COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
-			COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
+	
 
 			Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
 			Mat blurImg;
@@ -1362,8 +1361,7 @@ namespace OTSIMGPROC
 			auto s = downEdgeSeries.rbegin()->second;
 			pRangeFirst->SetEnd((long)(s[s.size() - 1]));
 		}
-		/*delete[] nBSEChart;
-		delete[] n_aBSEChart;*/
+	
 		return pRangeFirst;
 	}
 	void COTSImageProcess::RemoveBackGround(CBSEImgPtr a_pImgIn, COTSImageProcessParamPtr a_pImageProcessParam, CBSEImgPtr a_pBinImgOut,long& foundedPixelNum)
@@ -1378,34 +1376,31 @@ namespace OTSIMGPROC
 
 		long nImgSize = nWidthImg * nHeightImg;
 
-		BYTE* pTempImg = new BYTE[nImgSize];
-		BYTE* pTempImg2 = new BYTE[nImgSize];
+		BYTE* pTempImg = new BYTE[nImgSize];		
 
 		BYTE* pSrcImg = a_pImgIn->GetImageDataPointer();
 	
 
-	
-
-		
-
-	
 	     BYTE* pPixel = new byte[nImgSize];
 	
 		
 
 		long nBGStart;
 		long nBGEnd;
-
+		long nPartStart;
+		long nPartEnd;
 		long nNumParticle = 0;
 		if (a_pImageProcessParam->GetBGRemoveType() == OTS_BGREMOVE_TYPE::MANUAL)
 		{
 			nBGStart = a_pImageProcessParam->GetBGGray().GetStart();
 			nBGEnd = a_pImageProcessParam->GetBGGray().GetEnd();
+			nPartStart = a_pImageProcessParam->GetParticleGray().GetStart();
+			nPartEnd = a_pImageProcessParam->GetParticleGray().GetEnd();
 
 			// delete background 
 			for (unsigned int i = 0; i < nImgSize; i++)
 			{
-				if (pTempImg2[i] >= nBGStart && pTempImg2[i] <= nBGEnd)
+				if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
 				{
 					pPixel[i] = 0;
 				}
@@ -1414,14 +1409,17 @@ namespace OTSIMGPROC
 					pPixel[i] = 255;
 					nNumParticle++;
 				}
+				if (pSrcImg[i]<nPartStart || pSrcImg[i]>nPartEnd)
+				{
+					pPixel[i] = 0;
+				}
 			}
 			COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
 			COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
 		}
 		else
 		{
-			/*CBSEImgPtr srcImg2 = CBSEImgPtr(new CBSEImg());
-			srcImg2->SetImageData(a_pImgIn, nWidthImg, nHeightImg);*/
+		
 			auto range = CalBackground(a_pImgIn);
 			nBGStart = range->GetStart();
 
@@ -1433,7 +1431,7 @@ namespace OTSIMGPROC
 			case OTS_AUTOBGREMOVE_TYPE::DOWNWARD:
 				for (unsigned int i = 0; i < nImgSize; i++)
 				{
-					if (pTempImg2[i] <= nBGEnd)
+					if (pSrcImg[i] <= nBGEnd)
 					{
 						pPixel[i] = 0;
 					}
@@ -1447,7 +1445,7 @@ namespace OTSIMGPROC
 			case OTS_AUTOBGREMOVE_TYPE::UPWARD:
 				for (unsigned int i = 0; i < nImgSize; i++)
 				{
-					if (pTempImg2[i] >= nBGStart)
+					if (pSrcImg[i] >= nBGStart)
 					{
 						pPixel[i] = 0;
 					}
@@ -1461,7 +1459,7 @@ namespace OTSIMGPROC
 			case OTS_AUTOBGREMOVE_TYPE::MIDDLE:
 				for (unsigned int i = 0; i < nImgSize; i++)
 				{
-					if (pTempImg2[i] >= nBGStart && pTempImg2[i] <= nBGEnd)
+					if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
 					{
 						pPixel[i] = 0;
 					}
@@ -1482,7 +1480,7 @@ namespace OTSIMGPROC
 		
 		foundedPixelNum = nNumParticle;
 		delete[] pTempImg;
-		delete[] pTempImg2;
+		//delete[] pTempImg2;
 		return ;
 	}
 	BOOL COTSImageProcess::GetParticles(long left, long top, long a_nWidth, long a_nHeight, const BYTE* a_pPixel, COTSParticleList& a_listParticles)

+ 10 - 11
OTSIncAMeasureApp/0-OTSModel/OTSDataType/COTSSample.cs

@@ -1054,21 +1054,20 @@ namespace OTSDataType
                                         nItemId = OTS_SAMPLE_PROP_GRID_ITEMS.BG_GRAY_MAX;
                                         poPropItem.SetSmplParameter(modelResource, nItemId, OTS_ITEM_TYPES.INT, false, bShow);
                                         a_listPropItems.Add(poPropItem);
-                                    //here,no longer consider the gray range of particles,for we can get the same result by regulate the background range.(gsp 2021.8.13)
                                     //---------------------------------------
-                                    //// particle gray level min
+                                    // particle gray level min
 
-                                    //poPropItem = new CPropItem();
-                                    //nItemId = OTS_SAMPLE_PROP_GRID_ITEMS.PARTICLE_GRAY_MIN;
-                                    //poPropItem.SetSmplParameter(modelResource, nItemId, OTS_ITEM_TYPES.INT, false, bShow);
-                                    //a_listPropItems.Add(poPropItem);
+                                    poPropItem = new CPropItem();
+                                    nItemId = OTS_SAMPLE_PROP_GRID_ITEMS.PARTICLE_GRAY_MIN;
+                                    poPropItem.SetSmplParameter(modelResource, nItemId, OTS_ITEM_TYPES.INT, false, bShow);
+                                    a_listPropItems.Add(poPropItem);
 
-                                    //// particle gray level max
+                                    // particle gray level max
 
-                                    //poPropItem = new CPropItem();
-                                    //nItemId = OTS_SAMPLE_PROP_GRID_ITEMS.PARTICLE_GRAY_MAX;
-                                    //poPropItem.SetSmplParameter(modelResource, nItemId, OTS_ITEM_TYPES.INT, false, bShow);
-                                    //a_listPropItems.Add(poPropItem);
+                                    poPropItem = new CPropItem();
+                                    nItemId = OTS_SAMPLE_PROP_GRID_ITEMS.PARTICLE_GRAY_MAX;
+                                    poPropItem.SetSmplParameter(modelResource, nItemId, OTS_ITEM_TYPES.INT, false, bShow);
+                                    a_listPropItems.Add(poPropItem);
                                     //----------------------------------------
 
                                     // particle area min