// NoiseLevel.cpp: implementation of the CNoiseLevel class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "NoiseLevel.h" #include "SISBuffer.h" #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // ¿ÞÂÊ Çȼ¿¿¡ ¸¶Å©. -> ¿À¸¥ÂÊÀ¸·Î À妽º ÁøÇà. BOOL CNoiseLevel::DrawNoisePixel2Right(CSISBuffer &buffer, CSISBuffer &buffer2, double xPitch, int threshold, BYTE color, BOOL b32) { int x, y; int width= buffer.GetWidth()- (int)xPitch- 5; int level; if(b32) { for(x= 0; x< width; x++) { for(y= 0; y < buffer.GetHeight(); y++) { // level= buffer.GetPixel(x, y); // level= level- buffer.GetPixel(xPitch+ x, y); level= buffer.GetDiff32(x, y, xPitch)/6; if(level > threshold) buffer2.SetPixel(x, y, 255); else if(level < -threshold) buffer2.SetPixel(x, y, 0); } } }else { for(x= 0; x< width; x++) { for(y= 0; y < buffer.GetHeight(); y++) { level= buffer.GetPixel(x, y); level= level- buffer.GetPixel(xPitch+ x, y); if(level > threshold) buffer2.SetPixel(x, y, 255); else if(level < -threshold) buffer2.SetPixel(x, y, 0); } } } // int k= cov(noiseLevel, buffer, xPitch); return TRUE; } // ¿À¸¥ÂÊ Çȼ¿¿¡ ¸¶Å©. -> ¿ÞÂÊÀ¸·Î À妽º ÁøÇà BOOL CNoiseLevel::DrawNoisePixel2Left(CSISBuffer &buffer, CSISBuffer &buffer2, double xPitch, int threshold, BYTE color, BOOL b32) { int x, y; int width= buffer.GetWidth()- 1; int xs, xe; int level; if(b32) { xe= width- 3; xs= (int)(xPitch+ 3); for(x= xe; x >= xs; x--) { for(y= 0; y < buffer.GetHeight(); y++) { //level= buffer.GetPixel(x, y); //level= level- buffer.GetPixel(xPitch+ x, y); level= buffer.GetDiff32(x, y, -xPitch)/6; if(level > threshold) buffer2.SetPixel( x+ (int)(xPitch+ 0.5), y, 255); else if(level < -threshold) buffer2.SetPixel( x+ (int)(xPitch+ 0.5), y, 0); } } }else { for(x= width; x >= 0; x--) { for(y= 0; y < buffer.GetHeight(); y++) { level= buffer.GetPixel(x, y); level= level- buffer.GetPixel(xPitch+ x, y); if(level > threshold) buffer2.SetPixel( x+ (int)(xPitch+ 0.5), y, 255); else if(level < -threshold) buffer2.SetPixel( x+ (int)(xPitch+ 0.5), y, 0); } } } // int k= cov(noiseLevel, buffer, xPitch); return TRUE; } // ÇϺΠÇȼ¿¿¡ ¸¶Å©. -> À§ÂÊÀ¸·Î À妽º ÁøÇà. BOOL CNoiseLevel::DrawNoisePixel2Top(CSISBuffer &buffer, CSISBuffer &buffer2, double yPitch, int threshold, BYTE color, BOOL b23) { int x, y; int height= buffer.GetHeight()- (int)yPitch- 5; int level; int cCount= 0; if(b23) { for(y= height; y >= 0; y--) { for(x= 0; x < buffer.GetWidth(); x++) { // level= buffer.GetPixel(x, y); // level= level- buffer.GetPixel(x, yPitch+ y); level= buffer.GetDiff23(x, y, yPitch)/6; if(level > threshold) buffer2.SetPixel( x, y+ (int)(yPitch+ 0.5), 255); else if(level < -threshold) buffer2.SetPixel( x, y+ (int)(yPitch+ 0.5), 0); } } }else { for(y= height; y >= 0; y--) { for(x= 0; x < buffer.GetWidth(); x++) { level= buffer.GetPixel(x, y); level= level- buffer.GetPixel(x, yPitch+ y); //level= buffer.GetDiff23(x, y, yPitch)/6; if(level > threshold) buffer2.SetPixel( x, y+ (int)(yPitch+ 0.5), 255); else if(level < -threshold) buffer2.SetPixel( x, y+ (int)(yPitch+ 0.5), 0); } } } // int k= cov(noiseLevel, buffer, xPitch); return TRUE; } // »óºÎ Çȼ¿¿¡ ¸¶Å©. -> ¾Æ·¡ÂÊÀ¸·Î À妽º ÁøÇà. BOOL CNoiseLevel::DrawNoisePixel2Bottom(CSISBuffer &buffer, CSISBuffer &buffer2, double yPitch, int threshold, BYTE color, BOOL b23) { int x, y; int height= buffer.GetHeight()- (int)yPitch- 5; int level; if(b23) { for(y= 0; y< height; y++) { for(x= 0; x < buffer.GetWidth(); x++) { //level= buffer.GetPixel(x, y); //level= level- buffer.GetPixel(x, yPitch+ y); level= buffer.GetDiff23(x, y, yPitch)/6; if(level > threshold) buffer2.SetPixel( x, y, 255); else if(level < -threshold) buffer2.SetPixel( x, y, 0); } } }else { for(y= 0; y< height; y++) { for(x= 0; x < buffer.GetWidth(); x++) { level= buffer.GetPixel(x, y); level= level- buffer.GetPixel(x, yPitch+ y); //level= buffer.GetDiff23(x, y, yPitch)/6; if(level > threshold) buffer2.SetPixel( x, y, 255); else if(level < -threshold) buffer2.SetPixel( x, y, 0); } } } // int k= cov(noiseLevel, buffer, xPitch); return TRUE; } BOOL CNoiseLevel::FindXNoiseLevel(CSISBuffer &buffer, double xPitch, BOOL b32) { int x, y; int width= buffer.GetWidth()- (int)xPitch- 5; int level; m_Width= width; m_Height= buffer.GetHeight(); if(b32) { for(x= 0; x< width; x++) { for(y= 0; y < buffer.GetHeight(); y++) { // level= buffer.GetPixel(x, y); // level= level- buffer.GetPixel(xPitch+ x, y); level= buffer.GetDiff32(x, y, xPitch)/6; CountNoise(level); } } }else { for(x= 0; x< width; x++) { for(y= 0; y < buffer.GetHeight(); y++) { level= buffer.GetPixel(x, y); level= level- buffer.GetPixel(xPitch+ x, y); //level= buffer.GetDiff32(x, y, xPitch)/6; CountNoise(level); } } } // int k= cov(noiseLevel, buffer, xPitch); return TRUE; } BOOL CNoiseLevel::FindYNoiseLevel(CSISBuffer &buffer, double yPitch, BOOL b23) { int x, y; int height= buffer.GetHeight()- (int)yPitch- 5; int level; m_Width= buffer.GetWidth(); m_Height= height; if(b23) { for(y= 0; y< height; y++) { for(x= 0; x < buffer.GetWidth(); x++) { //level= buffer.GetPixel(x, y); //level= level- buffer.GetPixel(x, yPitch+ y); level= buffer.GetDiff23(x, y, yPitch)/6; CountNoise(level); } } }else { for(y= 0; y< height; y++) { for(x= 0; x < buffer.GetWidth(); x++) { level= buffer.GetPixel(x, y); level= level- buffer.GetPixel(x, yPitch+ y); //level= buffer.GetDiff23(x, y, yPitch)/6; CountNoise(level); } } } // int k= cov(noiseLevel, buffer, xPitch); return TRUE; } void CNoiseLevel::DrawNoiseLevel(CDC *pDC) { if(m_FoundThreshold <= 0) return; if(pDC == NULL) return; int noiseCount; int i; for(i= 0; i< 255; i++) { noiseCount= GetNoiseCount(i); if(noiseCount > 0) { pDC->MoveTo(i, 500); pDC->LineTo(i, 500- noiseCount); } } i= m_FoundThreshold- 3; if(i < 0) i= 0; TCHAR str[400]; _tprintf(str, _T("Thre:%d[%d-%d][%d/%d/%d]"), m_FoundThreshold, m_Width, m_Height, m_LimitCount, m_OverCount, m_TotalCount); for(; i< 255; i++) { noiseCount= GetNoiseCount(i); if(noiseCount > 0) { _tprintf(str, _T("%s, %d[%d]"), str, i, noiseCount); if(lstrlen(str) > 390) break; } } pDC->TextOut(50, 100, str); } int CNoiseLevel::CalFocusValue(CSISBuffer &buffer) { double Focusvalue = 0; double SumValue = 0; double TempValue = 0; int nWidth = buffer.GetWidth(); int nHeight = buffer.GetHeight(); LPBYTE pBuffer = buffer.GetDataAddress(0,0); if(pBuffer == NULL || nWidth <= 0 || nHeight <= 0) return 0; for(int y=0; y < nHeight-1; y++) { for(int x=0; x < nWidth-1; x++) { TempValue = (double)(pBuffer[y*nWidth+x]-pBuffer[y*nWidth+x+1]); SumValue = TempValue*TempValue; TempValue = (double)(pBuffer[y*nWidth+x]-pBuffer[(y+1)*nWidth+x]); SumValue += TempValue*TempValue; sqrt(SumValue); Focusvalue += SumValue; } } return int(Focusvalue/(double)nWidth); }