|
@@ -8,6 +8,7 @@
|
|
|
#include "OTSImageProcess.h"
|
|
|
#include "OTSImageProcessParam.h"
|
|
|
#include <OTSFieldData.h>
|
|
|
+#include "OTSMorphology.h"
|
|
|
#include "../OTSLog/COTSUtilityDllFunExport.h"
|
|
|
#include "FieldMgr.h"
|
|
|
using namespace cv;
|
|
@@ -15,6 +16,22 @@ using namespace std;
|
|
|
|
|
|
namespace OTSIMGPROC
|
|
|
{
|
|
|
+ // Re-magnification
|
|
|
+ const int nImage_Size = 3;
|
|
|
+
|
|
|
+ //make matrix filled with 255
|
|
|
+ const int nBlackColor = 255;
|
|
|
+
|
|
|
+ //make binary processing parameter 128
|
|
|
+ const int nProcessParam = 100;
|
|
|
+
|
|
|
+ //picture size
|
|
|
+ const int nPictureSize = 128;
|
|
|
+
|
|
|
+ // added to filtered pixels
|
|
|
+ const double delta = 0;
|
|
|
+
|
|
|
+ using namespace std;
|
|
|
namespace
|
|
|
{
|
|
|
|
|
@@ -291,748 +308,7 @@ namespace OTSIMGPROC
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- // use verticl line of 3 pixel to erode a image
|
|
|
- void COTSImageProcess::BErodeVertical3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y, wcounts;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 0; x < columns; x++)
|
|
|
- {
|
|
|
- *(target + x) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 0; x < columns; x++)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 0; x<columns; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + (DWORD)(y - 1)*columns + x) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
- if (*(source + (DWORD)(y + 1)*columns + x) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
-
|
|
|
- if (wcounts == 2) *(target + (DWORD)y*columns + x) = 255;
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- // use left 45 degree line of 3 pixel to erode a image
|
|
|
- void COTSImageProcess::BErodeLeft45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y, wcounts;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 0; x < columns; x++)
|
|
|
- {
|
|
|
- *(target + x) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 0; x < columns; x++)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- for (y = 1; y < rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x < columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + (DWORD)(y - 1)*columns + x - 1) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
- if (*(source + (DWORD)(y + 1)*columns + x + 1) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
-
|
|
|
- if (wcounts == 2) *(target + (DWORD)y*columns + x) = 255;
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- // use horizoontal line of 3 pixel to erode a image
|
|
|
- void COTSImageProcess::BErodeHorizontal3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y, wcounts;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + (DWORD)y*columns + x - 1) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
- if (*(source + (DWORD)y*columns + x + 1) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
-
|
|
|
- if (wcounts == 2) *(target + (DWORD)y*columns + x) = 255;
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- // use right 45 degree line of 3 pixel to erode a image
|
|
|
- void COTSImageProcess::BErodeRight45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y, wcounts;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 0; x < columns; x++)
|
|
|
- {
|
|
|
- *(target + x) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 0; x < columns; x++)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + (DWORD)(y - 1)*columns + x + 1) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
- if (*(source + (DWORD)(y + 1)*columns + x - 1) == 255)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
-
|
|
|
- if (wcounts == 2) *(target + (DWORD)y*columns + x) = 255;
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- void COTSImageProcess::BDilateVertical3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 0; x<columns; x++)
|
|
|
- {
|
|
|
- if (*(source + x) != 0)
|
|
|
- {
|
|
|
- *(target + x) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 0; x<columns; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)(rows - 1)*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0xff;
|
|
|
- *(target + (DWORD)(y - 1)*columns + x) = 255;
|
|
|
- *(target + (DWORD)(y + 1)*columns + x) = 255;
|
|
|
- }
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- void COTSImageProcess::BDilateLeft45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 0; x<columns; x++)
|
|
|
- {
|
|
|
- if (*(source + x) != 0)
|
|
|
- {
|
|
|
- *(target + x) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 0; x<columns; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)(rows - 1)*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + columns - 1) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0xff;
|
|
|
- *(target + (DWORD)(y - 1)*columns + x - 1) = 255;
|
|
|
- *(target + (DWORD)(y + 1)*columns + x + 1) = 255;
|
|
|
- }
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- void COTSImageProcess::BDilateHorizontal3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + columns - 1) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0xff;
|
|
|
- *(target + (DWORD)y*columns + x - 1) = 255;
|
|
|
- *(target + (DWORD)y*columns + x + 1) = 255;
|
|
|
- }
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- void COTSImageProcess::BDilateRight45Degree3(LPBYTE source, LPBYTE target, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y;
|
|
|
-
|
|
|
- if (rows <= 2 || columns <= 2)return;
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 0; x<columns; x++)
|
|
|
- {
|
|
|
- if (*(source + x) != 0)
|
|
|
- {
|
|
|
- *(target + x) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 0; x<columns; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)(rows - 1)*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 0; y<rows; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + columns - 1) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0xff;
|
|
|
- *(target + (DWORD)(y - 1)*columns + x + 1) = 255;
|
|
|
- *(target + (DWORD)(y + 1)*columns + x - 1) = 255;
|
|
|
- }
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- void COTSImageProcess::BErode3(LPBYTE source, LPBYTE target, WORD wDegree, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y, i, j, wcounts;
|
|
|
-
|
|
|
- if (rows == 1 || columns == 1)return;
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
|
|
|
-
|
|
|
- {
|
|
|
- for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) == 0)
|
|
|
- {
|
|
|
- wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree) *(target + (DWORD)y*columns + x) = 0;
|
|
|
- else *(target + (DWORD)y*columns + x) = 0xff;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 1; x<columns - (WORD)1; x++)
|
|
|
- {
|
|
|
- if (*(source + x) == 0)
|
|
|
- {
|
|
|
- *(target + x) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = 0; i <= 1; i++)
|
|
|
-
|
|
|
- {
|
|
|
- for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) == 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree * 5 / 8) *(target + x) = 0;
|
|
|
- else *(target + x) = 0xff;
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)(rows - 1)*columns + x) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(rows - 2); i <= (WORD)(rows - 1); i++)
|
|
|
-
|
|
|
- {
|
|
|
- for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) == 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree * 5 / 8) *(target + (DWORD)(rows - 1)*columns + x) = 0;
|
|
|
- else *(target + (DWORD)(rows - 1)*columns + x) = 0xff;
|
|
|
- }
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
|
|
|
- {
|
|
|
- for (j = 0; j <= 1; j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) == 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree * 5 / 8) *(target + (DWORD)y*columns) = 0;
|
|
|
- else *(target + (DWORD)y*columns) = 0xff;
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + columns - 1) == 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
|
|
|
-
|
|
|
- {
|
|
|
- for (j = (WORD)(columns - 2); j <= (WORD)(columns - 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) == 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree * 5 / 8) *(target + (DWORD)y*columns + columns - 1) = 0;
|
|
|
- else *(target + (DWORD)y*columns + columns - 1) = 0xff;
|
|
|
- }
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
- void COTSImageProcess::BDilate3(LPBYTE source, LPBYTE target, WORD wDegree, WORD rows, WORD columns)
|
|
|
- {
|
|
|
- WORD x, y, i, j, wcounts;
|
|
|
-
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + x) = 0xff;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
|
|
|
- {
|
|
|
- for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) != 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree) *(target + (DWORD)y*columns + x) = 0xff;
|
|
|
- else *(target + (DWORD)y*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // top line
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + x) != 0)
|
|
|
- {
|
|
|
- *(target + x) = 0xff;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = 0; i <= 1; i++)
|
|
|
- {
|
|
|
- for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) != 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (wcounts >= wDegree * 5 / 8) // but does not mater, as we have border of 2 now
|
|
|
- {
|
|
|
- *(target + x) = 0xff;
|
|
|
- }
|
|
|
- else { *(target + x) = 0; }
|
|
|
- }
|
|
|
-
|
|
|
- // bottom line
|
|
|
- for (x = 1; x<columns - 1; x++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)(rows - 1)*columns + x) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0xff;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(rows - 2); i <= (WORD)(rows - 1); i++)
|
|
|
- {
|
|
|
- for (j = (WORD)(x - 1); j <= (WORD)(x + 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) != 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (wcounts > wDegree * 5 / 8)
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *(target + (DWORD)(rows - 1)*columns + x) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // left line
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0xff;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
|
|
|
- {
|
|
|
- for (j = 0; j <= (WORD)1; j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) != 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree * 5 / 8)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // right line
|
|
|
- for (y = 1; y<rows - 1; y++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)y*columns + columns - 1) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0xff;
|
|
|
- continue;
|
|
|
- }
|
|
|
- wcounts = 0;
|
|
|
- for (i = (WORD)(y - 1); i <= (WORD)(y + 1); i++)
|
|
|
- {
|
|
|
- for (j = (WORD)(columns - 2); j <= (WORD)(columns - 1); j++)
|
|
|
- {
|
|
|
- if (*(source + (DWORD)i*columns + j) != 0) wcounts++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wcounts >= wDegree * 5 / 8)
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *(target + (DWORD)y*columns + columns - 1) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // four cornor points treated separately here
|
|
|
- // top-left
|
|
|
- if (*(source) != 0)
|
|
|
- {
|
|
|
- *target = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + 1) != 0) wcounts++;
|
|
|
- if (*(source + columns) != 0) wcounts++;
|
|
|
- if (*(source + columns + 1) != 0) wcounts++;
|
|
|
-
|
|
|
- // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
|
|
|
- if (wcounts * 8 >= wDegree * 3)
|
|
|
- {
|
|
|
- *target = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *target = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //top-right
|
|
|
- if (*(source + columns - 1) != 0)
|
|
|
- {
|
|
|
- *(target + columns - 1) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + columns - 2) != 0) wcounts++;
|
|
|
- if (*(source + columns * 2 - 1) != 0) wcounts++;
|
|
|
- if (*(source + columns * 2 - 2) != 0) wcounts++;
|
|
|
-
|
|
|
- // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
|
|
|
- if (wcounts * 8 >= wDegree * 3)
|
|
|
- {
|
|
|
- *(target + columns - 1) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *(target + columns - 1) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //bottom-left
|
|
|
- if (*(source + (DWORD)columns * (rows - 1)) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)columns * (rows - 1)) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + (DWORD)columns * (rows - 1) + 1) != 0) wcounts++;
|
|
|
- if (*(source + (DWORD)columns * (rows - 2)) != 0) wcounts++;
|
|
|
- if (*(source + (DWORD)columns * (rows - 2) + 1) != 0) wcounts++;
|
|
|
-
|
|
|
- // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
|
|
|
- if (wcounts * 8 >= wDegree * 3)
|
|
|
- {
|
|
|
- *(target + (DWORD)columns * (rows - 1)) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *(target + (DWORD)columns * (rows - 1)) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //bottom-right
|
|
|
- if (*(source + (DWORD)columns * rows - 1) != 0)
|
|
|
- {
|
|
|
- *(target + (DWORD)columns * rows - 1) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- wcounts = 0;
|
|
|
- if (*(source + (DWORD)columns * rows - 2) != 0) wcounts++;
|
|
|
- if (*(source + (DWORD)columns * (rows - 1) - 2) != 0) wcounts++;
|
|
|
- if (*(source + (DWORD)columns * (rows - 1) - 1) != 0) wcounts++;
|
|
|
-
|
|
|
- // if (wcounts >= wDegree*3/8) // this is a bug here - interger division
|
|
|
- if (wcounts * 8 >= wDegree * 3)
|
|
|
- {
|
|
|
- *(target + (DWORD)columns * rows - 1) = 0xff;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- *(target + (DWORD)columns * rows - 1) = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
// ReZoom the picture with re-magnification
|
|
|
BOOL COTSImageProcess::ReZoom(CString InPutPath, CString OutPutPath)
|
|
@@ -1090,25 +366,10 @@ namespace OTSIMGPROC
|
|
|
BOOL COTSImageProcess::RemoveBSEImageBG(CBSEImgPtr m_pBSEImg, COTSImageProcessParamPtr a_pImgProcessParam,COTSFieldDataPtr m_pFieldData)
|
|
|
{
|
|
|
ASSERT(m_pFieldData);
|
|
|
- if (!m_pFieldData)
|
|
|
- {
|
|
|
- LogErrorTrace(__FILE__, __LINE__, _T("RemoveBSEImageBG: there is no field data"));
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
|
|
|
ASSERT(m_pBSEImg);
|
|
|
- if (!m_pBSEImg)
|
|
|
- {
|
|
|
- LogErrorTrace(__FILE__, __LINE__, _T("RemoveBSEImageBG: there is no image data"));
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
|
|
|
ASSERT(a_pImgProcessParam);
|
|
|
- if (!a_pImgProcessParam)
|
|
|
- {
|
|
|
- LogErrorTrace(__FILE__, __LINE__, _T("RemoveBSEImageBG: there is no image process data"));
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
|
|
|
int nWidthImg = m_pBSEImg->GetWidth();
|
|
|
int nHeightImg = m_pBSEImg->GetHeight();
|
|
@@ -1891,8 +1152,8 @@ namespace OTSIMGPROC
|
|
|
//Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);// use the medianblur method to achieve the same effect as open morphology(errod and dialate).
|
|
|
//pPixel = cvcopyImg.data;
|
|
|
|
|
|
- COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
|
|
|
- COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
|
|
|
+ BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
|
|
|
+ BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
|
|
|
|
|
|
|
|
|
|
|
@@ -1920,7 +1181,7 @@ namespace OTSIMGPROC
|
|
|
BYTE* pSrcImg = a_pImgIn->GetImageDataPointer();
|
|
|
|
|
|
|
|
|
- BYTE* pPixel = new byte[nImgSize];
|
|
|
+ BYTE* pPixel = new byte[nImgSize];
|
|
|
|
|
|
|
|
|
|
|
@@ -1956,8 +1217,8 @@ namespace OTSIMGPROC
|
|
|
int errodDilateParam = a_pImageProcessParam->GetErrodDilateParam();
|
|
|
if (errodDilateParam > 0)
|
|
|
{
|
|
|
- COTSImageProcess::BErode3(pPixel, pTempImg, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
- COTSImageProcess::BDilate3(pTempImg, pPixel, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
+ BErode3(pPixel, pTempImg, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
+ BDilate3(pTempImg, pPixel, errodDilateParam, 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).
|
|
@@ -2025,8 +1286,8 @@ namespace OTSIMGPROC
|
|
|
int errodDilateParam = a_pImageProcessParam->GetErrodDilateParam();
|
|
|
if (errodDilateParam > 0)
|
|
|
{
|
|
|
- COTSImageProcess::BErode3(pPixel, pTempImg, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
- COTSImageProcess::BDilate3(pTempImg, pPixel, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
+ BErode3(pPixel, pTempImg, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
+ BDilate3(pTempImg, pPixel, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
}
|
|
|
/*Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
|
|
|
medianBlur(cvcopyImg, cvcopyImg, 5);
|
|
@@ -2596,53 +1857,7 @@ namespace OTSIMGPROC
|
|
|
a_pOTSPart->SetDInscr(MIN(w, h));
|
|
|
return true;
|
|
|
}
|
|
|
- // calculate the particle image data size, expand 3 pixel at the edge
|
|
|
- Mat particleImage = Mat::zeros(rect.Height() + nExpand_Size, rect.Width() + nExpand_Size, CV_8U);
|
|
|
- // get the segment list
|
|
|
- COTSSegmentsList listSegment = a_pOTSPart->GetFeature()->GetSegmentsList();
|
|
|
- for (auto pSegment : listSegment)
|
|
|
- {
|
|
|
- int nStart = pSegment->GetStart() - rect.left + nExpand_Size;
|
|
|
- int nEnd = pSegment->GetStart() + pSegment->GetLength() - rect.left - 1 + nExpand_Size;
|
|
|
- int nHeight = pSegment->GetHeight() - rect.top + nExpand_Size;
|
|
|
- line(particleImage, Point(nStart, nHeight), Point(nEnd, nHeight), Scalar(nBlackColor), nThickness, nLineType);
|
|
|
- }
|
|
|
- //--------abstract the contour of the particle.
|
|
|
- Mat cvcopyImg;
|
|
|
- medianBlur(particleImage, cvcopyImg, 5);//smooth the edge
|
|
|
- vector<vector<Point>>contours;
|
|
|
-
|
|
|
- findContours(cvcopyImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
|
|
|
- if (contours.size() == 0)// the particle is too odd that openCV can't find a contour of it. Then we take the upright rect of the particle as it's minArea rect.
|
|
|
- {
|
|
|
- double w = 0, h = 0;
|
|
|
- w = (double)rect.Width() * a_PixelSize;
|
|
|
- h = (double)rect.Height() * a_PixelSize;
|
|
|
- a_pOTSPart->SetDMax(MAX(w, h));
|
|
|
- a_pOTSPart->SetDMin(MIN(w, h));
|
|
|
- a_pOTSPart->SetDMean((w + h) / 2);
|
|
|
- a_pOTSPart->SetFeretDiameter((w + h) / 2);
|
|
|
- a_pOTSPart->SetDElong(MAX(w, h));
|
|
|
- a_pOTSPart->SetPerimeter((w + h) * 2);
|
|
|
- a_pOTSPart->SetDPerp(MIN(w, h));
|
|
|
- a_pOTSPart->SetDInscr(MIN(w, h));
|
|
|
- return true;
|
|
|
- }
|
|
|
- int imaxcontour = 0, imax = 0;
|
|
|
- for (unsigned int i = 0; i < contours.size(); i++) {
|
|
|
-
|
|
|
- int itmp = contourArea(contours[i]);
|
|
|
-
|
|
|
- if (imaxcontour < itmp) {
|
|
|
-
|
|
|
- imax = i;
|
|
|
-
|
|
|
- imaxcontour = itmp;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- vector<Point > listEdge = contours[imax];
|
|
|
+
|
|
|
if (a_XrayStep > 0)
|
|
|
{
|
|
|
COTSParticleList matricsParts;
|
|
@@ -2652,7 +1867,7 @@ namespace OTSIMGPROC
|
|
|
}
|
|
|
//-----------
|
|
|
}
|
|
|
- BOOL COTSImageProcess::SplitRawParticleIntoGreyScaleParticle(COTSParticlePtr a_pOTSPart, double a_PixelSize ,CBSEImgPtr fieldImg)
|
|
|
+ BOOL COTSImageProcess::SplitRawParticleIntoGreyScaleParticle(COTSParticlePtr a_pOTSPart,CDoubleRangePtr ecdRange, double a_PixelSize ,CBSEImgPtr fieldImg)
|
|
|
{
|
|
|
//--------- convert this particle data to image data,construct an image only with this particle.------
|
|
|
const int nExpand_Size = 3;
|
|
@@ -2696,7 +1911,7 @@ namespace OTSIMGPROC
|
|
|
}
|
|
|
/*ImshowImage(onePartImg);
|
|
|
ImshowChartData(onePartImg);*/
|
|
|
-
|
|
|
+ BlurImage(onePartImg);
|
|
|
std::vector<CIntRangePtr> rngs = CalcuGrayLevelRange(onePartImg);
|
|
|
|
|
|
|
|
@@ -2706,7 +1921,8 @@ namespace OTSIMGPROC
|
|
|
for (int i = 0; i < rngs.size(); i++)
|
|
|
{
|
|
|
partAreaMap.clear();
|
|
|
- GetParticlesBySpecialGrayRange(onePartImg, rngs[i], CDoubleRangePtr(new CDoubleRange(0, 2000)), a_PixelSize, partData);
|
|
|
+
|
|
|
+ GetParticlesBySpecialGrayRange(onePartImg, rngs[i], ecdRange, a_PixelSize, partData);
|
|
|
|
|
|
|
|
|
|
|
@@ -2738,6 +1954,7 @@ namespace OTSIMGPROC
|
|
|
|
|
|
}
|
|
|
theBiggestPart->GetFeature()->SetSegmentsList(partsegs, true);
|
|
|
+ theBiggestPart->CalCoverRect();
|
|
|
theBiggestPart->SetFieldId(a_pOTSPart->GetFieldId());
|
|
|
theBiggestPart->SetAnalysisId(a_pOTSPart->GetAnalysisId());
|
|
|
a_pOTSPart->AddSubParticle(theBiggestPart);
|
|
@@ -2796,6 +2013,20 @@ namespace OTSIMGPROC
|
|
|
|
|
|
cv::waitKey();
|
|
|
}
|
|
|
+ void COTSImageProcess::BlurImage(CBSEImgPtr inImg)
|
|
|
+ {
|
|
|
+ int rows, cols;
|
|
|
+ cols = inImg->GetWidth();
|
|
|
+ rows = inImg->GetHeight();
|
|
|
+ BYTE* pPixel = inImg->GetImageDataPointer();
|
|
|
+ Mat cvcopyImg = Mat(rows, cols, CV_8UC1, pPixel);
|
|
|
+ //Mat blurImg;
|
|
|
+ medianBlur(cvcopyImg, cvcopyImg, 7);//get rid of the noise point.
|
|
|
+ //cv::GaussianBlur(cvcopyImg, cvcopyImg, Size(3, 3), 7);
|
|
|
+ //inImg->SetImageData(cvcopyImg.data, width, height);
|
|
|
+ /*outImg = inImg;*/
|
|
|
+ }
|
|
|
+
|
|
|
BOOL COTSImageProcess::MergeBigBoundaryParticles(COTSFieldDataList allFields,double pixelSize,int scanFieldSize, CSize ResolutionSize, COTSParticleList& mergedParts)
|
|
|
{
|
|
|
COTSSegmentsList boarderSegs;
|