|
@@ -1281,44 +1281,32 @@ namespace OTSIMGPROC
|
|
|
|
|
|
return TRUE;
|
|
|
}
|
|
|
- BOOL COTSImageProcess::GetParticlesBySpecialGrayRange(CBSEImgPtr m_pBSEImg, CIntRangePtr a_grayRange, COTSFieldDataPtr m_pFieldData)
|
|
|
+ BOOL COTSImageProcess::GetParticlesBySpecialGrayRange(CBSEImgPtr a_pBSEImg, CIntRangePtr a_grayRange, COTSFieldDataPtr m_pFieldData)
|
|
|
{
|
|
|
ASSERT(m_pFieldData);
|
|
|
|
|
|
- ASSERT(m_pBSEImg);
|
|
|
+ ASSERT(a_pBSEImg);
|
|
|
|
|
|
ASSERT(a_grayRange);
|
|
|
|
|
|
|
|
|
- int nWidthImg = m_pBSEImg->GetWidth();
|
|
|
- int nHeightImg = m_pBSEImg->GetHeight();
|
|
|
+ int nWidthImg = a_pBSEImg->GetWidth();
|
|
|
+ int nHeightImg = a_pBSEImg->GetHeight();
|
|
|
m_pFieldData->Width = nWidthImg;
|
|
|
m_pFieldData->Height = nHeightImg;
|
|
|
long nImgSize = nWidthImg * nHeightImg;
|
|
|
|
|
|
|
|
|
- BYTE* pSrcImg = m_pBSEImg->GetImageDataPointer();
|
|
|
+ BYTE* pSrcImg = a_pBSEImg->GetImageDataPointer();
|
|
|
|
|
|
BYTE* pTempImg = new BYTE[nImgSize];
|
|
|
|
|
|
|
|
|
CBSEImgPtr imgNoBGBinary = CBSEImgPtr(new CBSEImg());
|
|
|
- CBSEImgPtr imgNoBGBinary1 = CBSEImgPtr(new CBSEImg());
|
|
|
+
|
|
|
long nNumParticle = 0;
|
|
|
- COTSImageProcessParamPtr a_pImageProcessParam = COTSImageProcessParamPtr(new COTSImageProcessParam());
|
|
|
- CIntRange lowRange ;
|
|
|
- CIntRange highRange;
|
|
|
- lowRange.SetStart(0);
|
|
|
- lowRange.SetEnd(a_grayRange->GetStart());
|
|
|
- highRange.SetStart(a_grayRange->GetEnd() + 1);
|
|
|
- highRange.SetEnd(255);
|
|
|
- a_pImageProcessParam->SetBGRemoveType((int)OTS_BGREMOVE_TYPE::MANUAL);
|
|
|
- a_pImageProcessParam->SetBGGray(lowRange);
|
|
|
- CIntRange partRange = CIntRange(0, 255);
|
|
|
- a_pImageProcessParam->SetParticleGray(partRange);
|
|
|
- RemoveBackGround(m_pBSEImg, a_pImageProcessParam, imgNoBGBinary1, nNumParticle);
|
|
|
- a_pImageProcessParam->SetBGGray(highRange);
|
|
|
- RemoveBackGround(imgNoBGBinary1, a_pImageProcessParam, imgNoBGBinary, nNumParticle);
|
|
|
+
|
|
|
+ GetSpecialGrayRangeImage(a_pBSEImg, a_grayRange, imgNoBGBinary, nNumParticle);
|
|
|
|
|
|
|
|
|
|
|
@@ -1527,6 +1515,61 @@ namespace OTSIMGPROC
|
|
|
|
|
|
return pRangeFirst;
|
|
|
}
|
|
|
+ void COTSImageProcess::GetSpecialGrayRangeImage(CBSEImgPtr a_pImgIn, CIntRangePtr a_SpecialGrayRange, CBSEImgPtr a_pBinImgOut, long& foundedPixelNum)
|
|
|
+ {
|
|
|
+ // the background pixel will be 0,and the other part will be 255.
|
|
|
+ ASSERT(a_pImgIn);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ int nWidthImg = a_pImgIn->GetWidth();
|
|
|
+ int nHeightImg = a_pImgIn->GetHeight();
|
|
|
+
|
|
|
+ long nImgSize = nWidthImg * nHeightImg;
|
|
|
+
|
|
|
+ BYTE* pTempImg = new BYTE[nImgSize];
|
|
|
+
|
|
|
+ BYTE* pSrcImg = a_pImgIn->GetImageDataPointer();
|
|
|
+
|
|
|
+
|
|
|
+ BYTE* pPixel = new byte[nImgSize];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ long nBGStart;
|
|
|
+ long nBGEnd;
|
|
|
+
|
|
|
+ long nNumParticle = 0;
|
|
|
+
|
|
|
+ nBGStart = a_SpecialGrayRange->GetStart();
|
|
|
+ nBGEnd = a_SpecialGrayRange->GetEnd();
|
|
|
+
|
|
|
+
|
|
|
+ // delete background
|
|
|
+ for (unsigned int i = 0; i < nImgSize; i++)
|
|
|
+ {
|
|
|
+ if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
|
|
|
+ {
|
|
|
+ pPixel[i] = 255;
|
|
|
+ nNumParticle++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pPixel[i] = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
|
|
|
+ COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
|
|
|
+
|
|
|
+ a_pBinImgOut->SetImageData(pPixel, nWidthImg, nHeightImg);
|
|
|
+
|
|
|
+ foundedPixelNum = nNumParticle;
|
|
|
+ delete[] pTempImg;
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
void COTSImageProcess::RemoveBackGround(CBSEImgPtr a_pImgIn, COTSImageProcessParamPtr a_pImageProcessParam, CBSEImgPtr a_pBinImgOut,long& foundedPixelNum)
|
|
|
{
|
|
|
// the background pixel will be 0,and the other part will be 255.
|