-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_code.txt
282 lines (247 loc) · 6.35 KB
/
4_code.txt
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
int level = 0;
void CimageprocessView::OnDraw(CDC* pDC)
{
CimageprocessDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
if(level==0)
mybmp1.Draw(pDC,CPoint(0,0),sizeDibDisplay1);
else if(level==1)
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp.Draw(pDC, CPoint(sizeDibDisplay1.cx, 0), sizeDibDisplay);
}
else if (level == 2)//灰度化
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp.Draw(pDC, CPoint(sizeDibDisplay1.cx, 0), sizeDibDisplay);
mybmp3.Draw(pDC, CPoint(sizeDibDisplay1.cx*2, 0), sizeDibDisplay);
}
else if (level==3)//二值化
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp2.Draw(pDC, CPoint(0, sizeDibDisplay1.cy), sizeDibDisplay2);
mybmp4.Draw(pDC, CPoint( sizeDibDisplay1.cx+2,0), sizeDibDisplay4);
}
else if (level == 5)//点运算
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp5.Draw(pDC, CPoint(sizeDibDisplay1.cx+2,0), sizeDibDisplay5);
}
else if (level == 6)//指数运算
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp.Draw(pDC, CPoint(sizeDibDisplay1.cx, 0), sizeDibDisplay);
mybmp6.Draw(pDC, CPoint(sizeDibDisplay1.cx*2,0), sizeDibDisplay6);
}
else if (level == 7)//直方图均衡化
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp.Draw(pDC, CPoint(sizeDibDisplay1.cx, 0), sizeDibDisplay);
mybmp7.Draw(pDC, CPoint(sizeDibDisplay1.cx * 2, 0), sizeDibDisplay7);
}
else if (level == 8)//强度分层法
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp.Draw(pDC, CPoint(sizeDibDisplay1.cx, 0), sizeDibDisplay);
mybmp7.Draw(pDC, CPoint(sizeDibDisplay1.cx * 2, 0), sizeDibDisplay7);
mybmp8.Draw(pDC, CPoint(0,sizeDibDisplay1.cy), sizeDibDisplay8);
}
else if (level == 9)//灰度变换法
{
mybmp1.Draw(pDC, CPoint(0, 0), sizeDibDisplay1);
mybmp.Draw(pDC, CPoint(sizeDibDisplay1.cx, 0), sizeDibDisplay);
mybmp7.Draw(pDC, CPoint(sizeDibDisplay1.cx * 2, 0), sizeDibDisplay7);
mybmp9.Draw(pDC, CPoint(0, sizeDibDisplay1.cy), sizeDibDisplay9);
}
mybmp2.Draw(pDC,CPoint(0,sizeDibDisplay1.cy),sizeDibDisplay2);
//显示一半尺度
/*CSize sizeTmp;
sizeTmp.cx = sizeDibDisplay2.cx/2;
sizeTmp.cy = sizeDibDisplay2.cy/2;
mybmp2.Draw(pDC,CPoint(sizeDibDisplay1.cx+10+sizeDibDisplay2.cx+10,0),sizeTmp);*/
}
1.**线性点运算
void CimageprocessView::Onlinear()
{
// TODO: 在此添加命令处理程序代码
// 对图象的象素值进行变换
// 每行
sizeDibDisplay5 = mybmp1.GetDimensions();
mybmp5.CreateCDib(sizeDibDisplay5, mybmp1.m_lpBMIH->biBitCount);
for (int y = 0; y < sizeDibDisplay1.cy; y++)
{
// 每列
for (int x = 0; x < sizeDibDisplay1.cx; x++)
{
RGBQUAD color;
color = mybmp1.GetPixel(x, y);
//s = ag + b
double g = color.rgbRed;
//线性变换参数
double a;
double b;
if (g >= 110)
{
a = 2.0;
b = 0;
g = a * g + b;
if (g >= 255)
g = 255;
}
else if (g < 88)
{
a = 0.2;
b = 0;
g = a * g + b;
}
else if (g > 88 && g < 100)
{
a = 0.5;
b = 0;
g = a * g + b;
}
else if (g > 100 && g < 110)
{
a = 1.3;
b = 0;
g = a * g + b;
}
color.rgbBlue = (unsigned char)g;
color.rgbGreen = (unsigned char)g;
color.rgbRed = (unsigned char)g;
mybmp5.WritePixel(x, y, color);
}
}
level = 5;
Invalidate();
}
2.**指数运算
void CimageprocessView::Onpower()
{
// TODO: 在此添加命令处理程序代码
sizeDibDisplay6 = mybmp.GetDimensions();
mybmp6.CreateCDib(sizeDibDisplay6, mybmp.m_lpBMIH->biBitCount);
// 对图象的象素值进行变换
// 每行
for (int y = 0; y < sizeDibDisplay6.cy; y++)
{
// 每列
for (int x = 0; x < sizeDibDisplay6.cx; x++)
{
RGBQUAD color;
color = mybmp.GetPixel(x, y);
double g = color.rgbRed;
double c = 10.0;
double a = 0.5;
g = c * pow(g, a);
color.rgbBlue = (unsigned char)g;
color.rgbGreen = (unsigned char)g;
color.rgbRed = (unsigned char)g;
mybmp6.WritePixel(x, y, color);
}
}
level = 6;
Invalidate();
}
3.**直方图均衡化
void CimageprocessView::OnHisequa()
{
// TODO: 在此添加命令处理程序代码
sizeDibDisplay7 = mybmp.GetDimensions();
mybmp7.CreateCDib(sizeDibDisplay7, mybmp.m_lpBMIH->biBitCount);
int count[256];
int newgray[256];
for (int i = 0;i < 256;i++)
{
count[i] = 0;
newgray[i] = 0;
}
for (int y = 0; y < sizeDibDisplay.cy; y++)
{
// 每行
for (int x = 0; x < sizeDibDisplay.cx; x++)
{
RGBQUAD color;
color = mybmp.GetPixel(x, y);
int gray = color.rgbBlue;
count[gray]++;
}
}
for (int i = 0; i < 256; i++)
{
int lTemp = 0;
for (int j = 0; j <= i; j++)
{
lTemp += count[j];
}
// 计算对应的新灰度值
newgray[i] = (lTemp * 255.0 / sizeDibDisplay.cy / sizeDibDisplay.cx);
}
for (int y = 0; y < sizeDibDisplay.cy; y++)
{
// 每行
for (int x = 0; x < sizeDibDisplay.cx; x++)
{
RGBQUAD color;
color = mybmp.GetPixel(x, y);
int gray = newgray[color.rgbBlue];
color.rgbBlue = (unsigned char)gray;
color.rgbGreen = (unsigned char)gray;
color.rgbRed = (unsigned char)gray;
mybmp7.WritePixel(x, y, color);
}
}
level =7;
Invalidate();
}
4. **强度分层法
void CimageprocessView::Onhierarchycolor()
{
sizeDibDisplay8= mybmp7.GetDimensions();
mybmp8.CreateCDib(sizeDibDisplay8, mybmp7.m_lpBMIH->biBitCount);
int graylevel =5;
RGBQUAD *color_tab = new RGBQUAD[graylevel + 1];
srand((unsigned int)time(NULL));
for (int i = 0; i <= graylevel; i++)
{
color_tab[i].rgbBlue = (unsigned char)rand() % 255;
color_tab[i].rgbGreen = (unsigned char)rand() % 255;
color_tab[i].rgbRed = (unsigned char)rand() % 255;
}
// 对图象的象素值进行变换
for (int x = 0; x < sizeDibDisplay1.cx; x++)
{
for (int y = 0; y < sizeDibDisplay1.cy; y++)
{
RGBQUAD color;
color = mybmp7.GetPixel(x, y);
int level = color.rgbBlue / 25; //对255个灰度等级的图像,分六种颜色
mybmp8.WritePixel(x, y, color_tab[level]);
}
}
level = 8;
Invalidate();
}
**灰度变换法:
void CimageprocessView::OnDensitranscolor()
{
// TODO: 在此添加命令处理程序代码
sizeDibDisplay9 = mybmp7.GetDimensions();
mybmp9.CreateCDib(sizeDibDisplay9, mybmp7.m_lpBMIH->biBitCount);
for (int x = 0; x < sizeDibDisplay9.cx; x++)
{
for (int y = 0; y < sizeDibDisplay9.cy; y++)
{
RGBQUAD color, color1;
color1 = mybmp7.GetPixel(x, y);
color.rgbRed = (int)((color1.rgbRed * 2 + 80) / 1 + 200);
color.rgbGreen = (int)((color1.rgbGreen * 4 + 120) / 3 + 20);
color.rgbBlue = (int)((color1.rgbBlue + 40) / 2 + 10);
mybmp9.WritePixel(x, y, color);
}
}
level = 9;
Invalidate();
}