#pragma once
|
|
#include "MosisAssem/AssemParam.h"
|
#include "MosisBuffer/MosisBuffer.h"
|
#include <math.h>
|
#include "MosisStorage.h"
|
|
class CReinspect;
|
|
|
typedef short SubMulti; // ¼ºêÇȼ¿ÀÇ ´ÜÀ§. 1/16 ¼ºêÇȼ¿À» »ç¿ë.
|
typedef short ImgDiff; // Â÷¿µ»ó À̹ÌÁöÀÇ °ªÀ» ÀúÀåÇÒ Å¸ÀÔ - short·Î ÀúÀå. ¸¸¾à ¿¬»êÀÌ ´Þ¶óÁú °æ¿ì °¢ ¿¬»êÀÇ °ªÀÌ short¸¦ ³ÑÁö ¾Ê³ª È®ÀÎ ÇÊ¿ä.
|
|
|
class CNoiseStat
|
{
|
public:
|
CNoiseStat(){m_Mean= 0; m_StdDeviation= 0; m_NoiseTh= 10; m_Rough= 0;}
|
|
float m_Mean;
|
float m_StdDeviation;
|
float m_NoiseTh; // ÀÚ¿¬ ³ëÀÌÁ ¹èÁ¦ Çϱâ À§ÇÑ ÀÓ°èÄ¡
|
float m_Rough;
|
void Reset() {m_Mean= 0; m_StdDeviation= 0;}
|
};
|
|
|
class CDiffBuff : public CMosisSquare<short>
|
{
|
public:
|
BOOL MakeDiffBuff(CMosisBuffer &src, CMosisBuffer &cmp, SubMulti s1, SubMulti s2, BOOL bVert= FALSE)
|
{
|
SetSize(src.GetWidth(), src.GetHeight());
|
|
BYTE *pSrc, *pCmp;
|
short *pDiff;
|
int pixelDist= 1;
|
|
int x, y;
|
SubMulti ssum;
|
ssum= s1+ s2;
|
|
ASSERT(ssum > 1);
|
short rslt;
|
|
if(bVert)
|
pixelDist= cmp.GetDataWidth();
|
|
for(y= 0; y< GetHeight(); y++)
|
{
|
x= 0;
|
pSrc= src.GetDataAddress(x, y);
|
pCmp= cmp.GetDataAddress(x, y);
|
pDiff= GetData(x, y);
|
for(; x< GetWidth(); x++)
|
{
|
rslt= *pSrc;
|
rslt= rslt- (s1*(*pCmp)+ s2*(*(pCmp+pixelDist)))/ssum;
|
*pDiff= rslt;
|
|
pSrc++;
|
pCmp++;
|
pDiff++;
|
}
|
}
|
return TRUE;
|
}
|
|
BOOL GetStatic(CNoiseStat &out, short* pData, int count)
|
{
|
INT64 sum= 0;
|
int realCount= 0;
|
float noise= out.m_NoiseTh;
|
short* pDiff= pData;
|
|
for(int x= 0; x< count; x++)
|
{
|
if(abs(*pDiff) > noise)
|
{
|
sum+= *pDiff;
|
realCount++;
|
}
|
pDiff++;
|
}
|
|
if(realCount < 1)
|
{
|
out.Reset();
|
return FALSE;
|
}
|
|
float mean= (float)sum;
|
out.m_Mean= mean= mean/realCount;
|
|
float diff, fsum= 0;
|
pDiff= pData;
|
int rough, roughsum= 0;
|
for(int x= 0; x< count; x++)
|
{
|
if(abs(*pDiff) > noise)
|
{
|
diff= *pDiff;
|
diff-= mean;
|
diff= diff*diff;
|
fsum+= diff;
|
}
|
if(x > 0)
|
roughsum+= abs(rough- *pDiff);
|
rough= *pDiff;
|
pDiff++;
|
}
|
if(count > 2)
|
out.m_Rough= (float)roughsum/realCount;
|
fsum/=realCount;
|
out.m_StdDeviation= sqrtf(fsum);
|
|
return TRUE;
|
}
|
|
BOOL GetStatic(CNoiseStat &out)
|
{
|
return GetStatic(out, GetAddress(), GetDataSize());
|
}
|
BOOL GetStatic(CNoiseStat & top, CNoiseStat &bottom)
|
{
|
int y= GetHeight()/2;
|
int size= y*GetWidth();
|
|
GetStatic(top, GetAddress(), size);
|
GetStatic(bottom, GetData(0, y), GetDataSize()- size);
|
|
return TRUE;
|
}
|
};
|
|
#define MOSIS_MEMORY_ALIGN 16
|
template<typename Ty>
|
class CTightBuff// 4byte ¾ó¶óÀÎÀ» »ç¿ëÇÏÁö ¾Ê´Â ¹öÆÛ.
|
{
|
protected:
|
Ty *m_pData;
|
int m_Width;
|
int m_Height;
|
int m_DataSpace;
|
public:
|
CTightBuff()
|
{
|
m_Width= 0;
|
m_Height= 0;
|
m_DataSpace= 0;
|
m_pData= NULL;
|
}
|
virtual ~CTightBuff()
|
{
|
ReleaseSpace();
|
}
|
Ty *GetDataAddress(){return m_pData;}
|
Ty *GetDataAddress(int x, int y){return m_pData+ x+ y*GetWidth();}
|
int GetWidth(){return m_Width;}
|
int GetHeight(){return m_Height;}
|
int GetDataSize(){return GetWidth()*GetHeight();}
|
BOOL IsValidBuffer(){return (m_pData != NULL) && (m_Width>0) && (m_Height>0);}
|
|
void ReleaseSpace()
|
{
|
if(m_pData)
|
{
|
#if defined(MOSIS_MEMORY_ALIGN)
|
_mm_free(m_pData);
|
#else
|
delete[] m_pData;
|
#endif
|
}
|
m_pData= NULL;
|
m_Width= 0;
|
m_Height= 0;
|
m_DataSpace= 0;
|
}
|
BOOL SetSize(int width, int height)
|
{
|
int space= width*height;
|
if(space < 1)
|
return FALSE;
|
|
if(m_DataSpace < space)
|
{
|
ReleaseSpace();
|
}
|
|
if(m_pData == NULL)
|
{
|
#if defined(MOSIS_MEMORY_ALIGN)
|
m_pData= (Ty*)_mm_malloc(space*sizeof(Ty), MOSIS_MEMORY_ALIGN);
|
#else
|
m_pData= new Ty[space];
|
#endif
|
m_DataSpace= space;
|
}
|
|
m_Width= width;
|
m_Height= height;
|
return IsValidBuffer();
|
}
|
int GetIndex(int x, int y) {return x+ y*GetWidth();}
|
void SetPixel(int x, int y, Ty val)
|
{
|
*(m_pData+ x+ y*GetWidth())= val;
|
}
|
|
public:
|
BOOL MakeDiffBuff(CMosisBuffer &src, CMosisBuffer &cmp, SubMulti s1, SubMulti s2, BOOL bVert= FALSE)
|
{
|
SetSize(src.GetWidth(), src.GetHeight());
|
|
BYTE *pSrc, *pCmp;
|
Ty *pDiff;
|
int pixelDist= 1;
|
|
int x, y;
|
SubMulti ssum;
|
ssum= s1+ s2;
|
|
ASSERT(ssum > 1);
|
Ty rslt;
|
|
if(bVert)
|
pixelDist= cmp.GetDataWidth();
|
|
for(y= 0; y< GetHeight(); y++)
|
{
|
x= 0;
|
pSrc= src.GetDataAddress(x, y);
|
pCmp= cmp.GetDataAddress(x, y);
|
pDiff= GetDataAddress(x, y);
|
for(; x< GetWidth(); x++)
|
{
|
rslt= *pSrc;
|
rslt= rslt- (s1*(*pCmp)+ s2*(*(pCmp+pixelDist)))/ssum;
|
*pDiff= rslt;
|
|
pSrc++;
|
pCmp++;
|
pDiff++;
|
}
|
}
|
return TRUE;
|
}
|
|
BOOL GetStatic(CNoiseStat &out, Ty* pData, int count)
|
{
|
INT64 sum= 0;
|
int realCount= 0;
|
float noise= out.m_NoiseTh;
|
Ty* pDiff= pData;
|
|
for(int x= 0; x< count; x++)
|
{
|
if(abs(*pDiff) > noise)
|
{
|
sum+= *pDiff;
|
realCount++;
|
}
|
pDiff++;
|
}
|
|
if(realCount < 1)
|
{
|
out.Reset();
|
return FALSE;
|
}
|
|
float mean= sum;
|
out.m_Mean= mean= mean/realCount;
|
|
float diff, fsum= 0;
|
pDiff= pData;
|
int rough, roughsum= 0;
|
for(int x= 0; x< count; x++)
|
{
|
if(abs(*pDiff) > noise)
|
{
|
diff= *pDiff;
|
diff-= mean;
|
diff= diff*diff;
|
fsum+= diff;
|
}
|
if(x > 0)
|
roughsum+= abs(rough- *pDiff);
|
rough= *pDiff;
|
pDiff++;
|
}
|
if(count > 2)
|
out.m_Rough= (float)roughsum/realCount;
|
fsum/=realCount;
|
out.m_StdDeviation= sqrtf(fsum);
|
|
return TRUE;
|
}
|
|
BOOL GetStatic(CNoiseStat &out)
|
{
|
return GetStatic(out, GetDataAddress(), GetDataSize());
|
}
|
BOOL GetStatic(CNoiseStat & top, CNoiseStat &bottom)
|
{
|
int y= GetHeight()/2;
|
int size= y*GetWidth();
|
|
GetStatic(top, GetDataAddress(), size);
|
GetStatic(bottom, GetDataAddress(0, y), GetDataSize()- size);
|
|
return TRUE;
|
}
|
};
|