SDC C-Project CF Review 프로그램
LYW
2021-09-27 b9b6752e83c701cc67241923d2b74dc3a963d243
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// NoiseLevel.h: interface for the CNoiseLevel class.
//
//////////////////////////////////////////////////////////////////////
 
#if !defined(AFX_NOISELEVEL_H__5D3B57CE_14F1_4CD6_8D25_25471A55B874__INCLUDED_)
#define AFX_NOISELEVEL_H__5D3B57CE_14F1_4CD6_8D25_25471A55B874__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
 
class CMosisBuffer;
typedef unsigned char BYTE;
 
// 1. FindXNoiseLevel °è¿­·Î Noise¸¦ µ¥ÀÌÅÍ È®º¸.
// 2. RecommendThreshold(1, 2, 3) 3°¡Áö ¹æ¹ýÀ¸·Î Threshold µµÃâ.
 
 
class AFX_EXT_CLASS CNoiseLevel  
{
public:
    int m_TotalCount;
    int    m_OverCount;
    double    m_Ratio;
    int    m_LimitCount;
    int m_pnNoisePixel[256];
    int m_FoundThreshold;
    int    m_Width, m_Height;
 
    void ResetCount()
    {
        for(int i= 0; i< 256; i++)
        {
            m_pnNoisePixel[i]= 0;
        }
        m_TotalCount= 0;
        m_FoundThreshold= -1;
    }
    int GetNoiseCount(int level)
    {
        if(level < 0)
            level= -level;
        ASSERT(level < 256);
        return m_pnNoisePixel[level];
    }
    int CountNoise(int level)
    {
        if(level < 0)
            level= -level;
        ASSERT(level < 256);
        m_pnNoisePixel[level]++;
        m_TotalCount++;
        return m_pnNoisePixel[level];
    }
 
 
public:
    // 1. ³ëÀÌÁî°¡ Å« °ÍºÎÅ͠Ž»öÇØ limitCount º¸´Ù ³ôÀº Á¡ÀÌ ¹ß»ýÇϸé Threshold·Î Ãßõ.. ±ú²ýÇÑ À̹ÌÁö¿¡ ÀûÇÕ.
    int RecommendThreshold1(double fNoiseLimit= 0.001)
    {
        m_LimitCount= (int)(m_TotalCount*fNoiseLimit);
        if(m_LimitCount < 1)
            m_LimitCount= 1;
        return RecommendThreshold(m_LimitCount);
    }
    int RecommendThreshold(int nLimitCount)
    {
        m_OverCount= 0;
        for(int i= 255; i>= 0; i--)
        {
            m_OverCount+= m_pnNoisePixel[i];
            if(m_pnNoisePixel[i] >= nLimitCount)
            {
                m_OverCount-= m_pnNoisePixel[i];
                m_FoundThreshold= i;
                return m_FoundThreshold;
            }
        }
        m_FoundThreshold= 0;
        return 0;
    }
 
    // 2. ³ëÀÌÁî°¡ ÀÛÀº °ÍºÎÅÍ ½ÃÀÛÇØ limitcountÀÌÇϷΠ¶³¾îÁö±â ½ÃÀÛÇϴ Á¡À» Ã£´Â´Ù... ³ëÀÌÁî ¸¹Àº À̹ÌÁö¿¡ ÀûÇÕ.
    int RecommendThreshold2(double fNoiseLimit= 0.001)
    {
        m_OverCount= m_TotalCount;
        m_LimitCount= (int)(m_TotalCount*fNoiseLimit);
        if(m_LimitCount < 1)
            m_LimitCount= 1;
        for(int i= 0; i< 256; i++)
        {
            m_OverCount-= m_pnNoisePixel[i];
            if(m_pnNoisePixel[i] <= m_LimitCount)
            {
                m_FoundThreshold= i;
                return i;
            }
        }
        m_FoundThreshold= 0;
        return 0;
    }
 
    // 3. ³ëÀÌÁî°¡ ³ôÀº ÂÊ¿¡¼­ ºÎÅÍ ´©ÀûÀûÀ¸·ç´Ù°¡ °è»êÇØ¼­ limitcount¸¦ ³Ñ´Â ³ðÀ» Threshold·Î Ãßõ. ¾ÈÀü»§¿¡ ÀûÇÕ.
    int RecommendThreshold3(double fNoiseLimit= 0.001)
    {
        m_LimitCount= (int)(m_TotalCount*fNoiseLimit);
        if(m_LimitCount < 1)
            m_LimitCount= 1;
        return RecommendThresholdAccumulative(m_LimitCount);
    }
    // Threshold¸¦ ³·Ãç°¡¸é nNoiseLimet °³¼ö ÀÌ»óÀÇ °áÇÔ Çȼ¿ÀÌ ¹ß»ýÇϸ頱נ¼±À» Threshold·Î ÇÑ´Ù.
    int RecommendThresholdAccumulative(int nLimitCount)
    {
        int nCount= 0;
        for(int i= 255; i>= 0; i--)
        {
            nCount+= m_pnNoisePixel[i];
            if(nCount >= nLimitCount)
            {
                m_OverCount= nCount-  m_pnNoisePixel[i];
                m_FoundThreshold= i;
                return i;
            }
        }
        m_FoundThreshold= 0;
        return 0;
    }
 
public:
    CNoiseLevel()            {ResetCount();}
 
    BOOL FindXNoiseLevel(CMosisBuffer &buffer, double xPitch, BOOL b32= TRUE);
    BOOL FindYNoiseLevel(CMosisBuffer &buffer, double yPitch, BOOL b23= TRUE);
 
    BOOL DrawNoisePixel2Left(CMosisBuffer &buffer, CMosisBuffer &buffer2, double pitch, int threshold, BYTE color, BOOL b32= TRUE);
    BOOL DrawNoisePixel2Right(CMosisBuffer &buffer, CMosisBuffer &buffer2, double pitch, int threshold, BYTE color, BOOL b32= TRUE);
    BOOL DrawNoisePixel2Top(CMosisBuffer &buffer, CMosisBuffer &buffer2, double pitch, int threshold, BYTE color, BOOL b23= TRUE);
    BOOL DrawNoisePixel2Bottom(CMosisBuffer &buffer, CMosisBuffer &buffer2, double pitch, int threshold, BYTE color, BOOL b23= TRUE);
    void DrawNoiseLevel(CDC *pDC);
 
    //////////////////////////////////////////////////////////////////////////
    // Focus Value
    int    CalFocusValue(CMosisBuffer &buffer);
 
};
 
#endif // !defined(AFX_NOISELEVEL_H__5D3B57CE_14F1_4CD6_8D25_25471A55B874__INCLUDED_)