質問編集履歴
2
インシデントを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,252 +52,260 @@
|
|
52
52
|
|
53
53
|
{
|
54
54
|
|
55
|
-
public partial class Form1 : Form
|
55
|
+
public partial class Form1 : Form
|
56
|
-
|
56
|
+
|
57
|
-
{
|
57
|
+
{
|
58
|
-
|
58
|
+
|
59
|
-
public Form1()
|
59
|
+
public Form1()
|
60
|
-
|
60
|
+
|
61
|
-
{
|
61
|
+
{
|
62
|
-
|
62
|
+
|
63
|
-
InitializeComponent();
|
63
|
+
InitializeComponent();
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Bitmap bmp1_im1;//資料画像(原画像)のビットマップ
|
70
|
+
|
71
|
+
Bitmap bmp1_im2;//資料画像(二値化後)のビットマップ
|
72
|
+
|
73
|
+
Bitmap bmp1_im3;//資料画像(フィルタ処理後)のビットマップ
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
PictureBox pb1, pb2, pb3;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
private void Form1_Load(object sender, EventArgs e)
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
pb1 = pictureBox1;
|
86
|
+
|
87
|
+
pb2 = pictureBox2;
|
88
|
+
|
89
|
+
pb3 = pictureBox3;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
private void File_Open_Click(object sender, EventArgs e)
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
Image im1 = Image.FromFile(openFileDialog1.FileName);
|
106
|
+
|
107
|
+
DrawPicture1(im1);
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
private void DrawPicture1(Image im1)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
double a;
|
122
|
+
|
123
|
+
int maxsize = 200;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
if (im1.Width < maxsize && im1.Height < maxsize)
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
pb1.Width = pb1.Height = maxsize;
|
132
|
+
|
133
|
+
Rectangle rect1 = new Rectangle(0, 0, im1.Width, im1.Height);//イメージのサイズ
|
134
|
+
|
135
|
+
Rectangle rect2 = new Rectangle(0, 0, pb1.Width, pb1.Height);//PictureBox1のサイズ
|
136
|
+
|
137
|
+
bmp1_im1 = new Bitmap(pb1.Width, pb1.Height);
|
138
|
+
|
139
|
+
Graphics g = Graphics.FromImage(bmp1_im1);
|
140
|
+
|
141
|
+
g.DrawImage(im1, rect2, rect1, GraphicsUnit.Pixel);
|
142
|
+
|
143
|
+
g.Dispose();
|
144
|
+
|
145
|
+
pb1.Image = bmp1_im1;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
else
|
150
|
+
|
151
|
+
{
|
152
|
+
|
153
|
+
if (im1.Width > im1.Height)
|
154
|
+
|
155
|
+
{
|
156
|
+
|
157
|
+
/*a = (double)maxsize / (double)im1.Width;*/
|
158
|
+
|
159
|
+
pb1.Width = maxsize;
|
160
|
+
|
161
|
+
pb1.Height = maxsize /* (int)(a * im1.Height)*/;
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
else
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
/*a = (double)maxsize / (double)im1.Height;*/
|
170
|
+
|
171
|
+
pb1.Height = maxsize;
|
172
|
+
|
173
|
+
pb1.Width =maxsize /*(int)(a * im1.Width)*/;
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
Rectangle rect3 = new Rectangle(0, 0, im1.Width, im1.Height);//イメージのサイズ
|
178
|
+
|
179
|
+
Rectangle rect4 = new Rectangle(0, 0, pb1.Width, pb1.Height);//PictureBox1のサイズ
|
180
|
+
|
181
|
+
bmp1_im1 = new Bitmap(pb1.Width, pb1.Height);
|
182
|
+
|
183
|
+
Graphics g = Graphics.FromImage(bmp1_im1);
|
184
|
+
|
185
|
+
g.DrawImage(im1, rect4, rect3, GraphicsUnit.Pixel);
|
186
|
+
|
187
|
+
g.Dispose();
|
188
|
+
|
189
|
+
pb1.Image = bmp1_im1;
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
private void File_SaveBMP_Click(object sender, EventArgs e)
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
pb2.Image.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
private void P_GrayScale_Click(object sender, EventArgs e)
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
int i, j, nx, ny;
|
218
|
+
|
219
|
+
int gray;
|
220
|
+
|
221
|
+
Color col;
|
222
|
+
|
223
|
+
nx = pb3.Width;
|
224
|
+
|
225
|
+
ny = pb3.Height;
|
226
|
+
|
227
|
+
bmp1_im2 = new Bitmap (pb3.Image);
|
228
|
+
|
229
|
+
for (j = 0; j < ny; j++)
|
230
|
+
|
231
|
+
for (i = 0; i < nx; i++)
|
232
|
+
|
233
|
+
{
|
234
|
+
|
235
|
+
col = bmp1_im2.GetPixel(i, j);
|
236
|
+
|
237
|
+
if (col.R > 200 && col.B > 200 && col.G > 200) gray = 255;
|
238
|
+
|
239
|
+
else gray = 0;
|
240
|
+
|
241
|
+
bmp1_im2.SetPixel(i, j, Color.FromArgb(gray, gray, gray));
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
pb2.Image = bmp1_im2;
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
private void gausian_Click(object sender, EventArgs e)
|
254
|
+
|
255
|
+
{
|
256
|
+
|
257
|
+
int nx, ny;
|
258
|
+
|
259
|
+
int gray;
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
nx = pb1.Width;
|
264
|
+
|
265
|
+
ny = pb1.Height;
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
// 画像の読み込み(グレースケールに変換)
|
270
|
+
|
271
|
+
bmp1_im3 = new Bitmap(pb1.Image);
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
// フィルタ用のカーネル
|
276
|
+
|
277
|
+
const int kernelSize = 3; // カーネルサイズ
|
278
|
+
|
279
|
+
double[,] kernel = new double[kernelSize, kernelSize]{
|
280
|
+
|
281
|
+
{1/16.0, 1/8.0, 1/16.0},
|
282
|
+
|
283
|
+
{1/8.0, 1/4.0, 1/8.0},
|
284
|
+
|
285
|
+
{1/16.0, 1/8.0, 1/16.0}};
|
286
|
+
|
287
|
+
/* フィルタ処理
|
288
|
+
|
289
|
+
bmp1_im3 = Filter(pb3.Image, kernel);
|
290
|
+
|
291
|
+
*/
|
292
|
+
|
293
|
+
pb3.Image = bmp1_im3;
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
}
|
64
306
|
|
65
307
|
}
|
66
308
|
|
67
|
-
|
68
|
-
|
69
|
-
Bitmap bmp1_im1;//資料画像(原画像)のビットマップ
|
70
|
-
|
71
|
-
Bitmap bmp1_im2;//資料画像(二値化後)のビットマップ
|
72
|
-
|
73
|
-
Bitmap bmp1_im3;//資料画像(フィルタ処理後)のビットマップ
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
PictureBox pb1, pb2, pb3;
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
private void Form1_Load(object sender, EventArgs e)
|
82
|
-
|
83
|
-
{
|
84
|
-
|
85
|
-
pb1 = pictureBox1;
|
86
|
-
|
87
|
-
pb2 = pictureBox2;
|
88
|
-
|
89
|
-
pb3 = pictureBox3;
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
private void File_Open_Click(object sender, EventArgs e)
|
98
|
-
|
99
|
-
{
|
100
|
-
|
101
|
-
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
102
|
-
|
103
|
-
{
|
104
|
-
|
105
|
-
Image im1 = Image.FromFile(openFileDialog1.FileName);
|
106
|
-
|
107
|
-
DrawPicture1(im1);
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
private void DrawPicture1(Image im1)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
{
|
120
|
-
|
121
|
-
double a;
|
122
|
-
|
123
|
-
int maxsize = 200;
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
if (im1.Width < maxsize && im1.Height < maxsize)
|
128
|
-
|
129
|
-
{
|
130
|
-
|
131
|
-
pb1.Width = pb1.Height = maxsize;
|
132
|
-
|
133
|
-
Rectangle rect1 = new Rectangle(0, 0, im1.Width, im1.Height);//イメージのサイズ
|
134
|
-
|
135
|
-
Rectangle rect2 = new Rectangle(0, 0, pb1.Width, pb1.Height);//PictureBox1のサイズ
|
136
|
-
|
137
|
-
bmp1_im1 = new Bitmap(pb1.Width, pb1.Height);
|
138
|
-
|
139
|
-
Graphics g = Graphics.FromImage(bmp1_im1);
|
140
|
-
|
141
|
-
g.DrawImage(im1, rect2, rect1, GraphicsUnit.Pixel);
|
142
|
-
|
143
|
-
g.Dispose();
|
144
|
-
|
145
|
-
pb1.Image = bmp1_im1;
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
else
|
150
|
-
|
151
|
-
{
|
152
|
-
|
153
|
-
if (im1.Width > im1.Height)
|
154
|
-
|
155
|
-
{
|
156
|
-
|
157
|
-
/*a = (double)maxsize / (double)im1.Width;*/
|
158
|
-
|
159
|
-
pb1.Width = maxsize;
|
160
|
-
|
161
|
-
pb1.Height = maxsize /* (int)(a * im1.Height)*/;
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
else
|
166
|
-
|
167
|
-
{
|
168
|
-
|
169
|
-
/*a = (double)maxsize / (double)im1.Height;*/
|
170
|
-
|
171
|
-
pb1.Height = maxsize;
|
172
|
-
|
173
|
-
pb1.Width =maxsize /*(int)(a * im1.Width)*/;
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
Rectangle rect3 = new Rectangle(0, 0, im1.Width, im1.Height);//イメージのサイズ
|
178
|
-
|
179
|
-
Rectangle rect4 = new Rectangle(0, 0, pb1.Width, pb1.Height);//PictureBox1のサイズ
|
180
|
-
|
181
|
-
bmp1_im1 = new Bitmap(pb1.Width, pb1.Height);
|
182
|
-
|
183
|
-
Graphics g = Graphics.FromImage(bmp1_im1);
|
184
|
-
|
185
|
-
g.DrawImage(im1, rect4, rect3, GraphicsUnit.Pixel);
|
186
|
-
|
187
|
-
g.Dispose();
|
188
|
-
|
189
|
-
pb1.Image = bmp1_im1;
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
private void File_SaveBMP_Click(object sender, EventArgs e)
|
198
|
-
|
199
|
-
{
|
200
|
-
|
201
|
-
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
202
|
-
|
203
|
-
{
|
204
|
-
|
205
|
-
pb2.Image.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
private void P_GrayScale_Click(object sender, EventArgs e)
|
214
|
-
|
215
|
-
{
|
216
|
-
|
217
|
-
int i, j, nx, ny;
|
218
|
-
|
219
|
-
int gray;
|
220
|
-
|
221
|
-
Color col;
|
222
|
-
|
223
|
-
nx = pb3.Width;
|
224
|
-
|
225
|
-
ny = pb3.Height;
|
226
|
-
|
227
|
-
bmp1_im2 = new Bitmap (pb3.Image);
|
228
|
-
|
229
|
-
for (j = 0; j < ny; j++)
|
230
|
-
|
231
|
-
for (i = 0; i < nx; i++)
|
232
|
-
|
233
|
-
{
|
234
|
-
|
235
|
-
col = bmp1_im2.GetPixel(i, j);
|
236
|
-
|
237
|
-
if (col.R > 200 && col.B > 200 && col.G > 200) gray = 255;
|
238
|
-
|
239
|
-
else gray = 0;
|
240
|
-
|
241
|
-
bmp1_im2.SetPixel(i, j, Color.FromArgb(gray, gray, gray));
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
pb2.Image = bmp1_im2;
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
private void gausian_Click(object sender, EventArgs e)
|
252
|
-
|
253
|
-
{
|
254
|
-
|
255
|
-
int nx, ny;
|
256
|
-
|
257
|
-
int gray;
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
nx = pb1.Width;
|
262
|
-
|
263
|
-
ny = pb1.Height;
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
// 画像の読み込み(グレースケールに変換)
|
268
|
-
|
269
|
-
bmp1_im3 = new Bitmap(pb1.Image);
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
// フィルタ用のカーネル
|
274
|
-
|
275
|
-
const int kernelSize = 3; // カーネルサイズ
|
276
|
-
|
277
|
-
double[,] kernel = new double[kernelSize, kernelSize]{
|
278
|
-
|
279
|
-
{1/16.0, 1/8.0, 1/16.0},
|
280
|
-
|
281
|
-
{1/8.0, 1/4.0, 1/8.0},
|
282
|
-
|
283
|
-
{1/16.0, 1/8.0, 1/16.0}};
|
284
|
-
|
285
|
-
/* フィルタ処理
|
286
|
-
|
287
|
-
bmp1_im3 = Filter(pb3.Image, kernel); ←ここの部分です
|
288
|
-
|
289
|
-
*/
|
290
|
-
|
291
|
-
pb3.Image = bmp1_im3;
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
309
|
```
|
302
310
|
|
303
311
|
|
1
Markdownを利用するように言われたので、そこを修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,12 +1,30 @@
|
|
1
|
-
|
1
|
+
### 前提・実現したいこと
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
-
C#で画像処理
|
5
|
+
C#で元画像をガウシアンフィルタでフィルタ処理した後に、二値化するという作業をしています。
|
6
|
+
|
6
|
-
|
7
|
+
フィルタ機能を実装中に以下のエラーメッセージが発生しました。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
### 発生している問題・エラーメッセージ
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
```
|
16
|
+
|
7
|
-
|
17
|
+
名前'Filter'は現在のコンテキスト内に存在しません。
|
18
|
+
|
8
|
-
|
19
|
+
```
|
20
|
+
|
21
|
+
|
22
|
+
|
9
|
-
|
23
|
+
### 該当のソースコード
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```C#
|
10
28
|
|
11
29
|
using System;
|
12
30
|
|
@@ -34,257 +52,261 @@
|
|
34
52
|
|
35
53
|
{
|
36
54
|
|
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
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
55
|
+
public partial class Form1 : Form
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
public Form1()
|
60
|
+
|
61
|
+
{
|
62
|
+
|
63
|
+
InitializeComponent();
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Bitmap bmp1_im1;//資料画像(原画像)のビットマップ
|
70
|
+
|
71
|
+
Bitmap bmp1_im2;//資料画像(二値化後)のビットマップ
|
72
|
+
|
73
|
+
Bitmap bmp1_im3;//資料画像(フィルタ処理後)のビットマップ
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
PictureBox pb1, pb2, pb3;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
private void Form1_Load(object sender, EventArgs e)
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
pb1 = pictureBox1;
|
86
|
+
|
87
|
+
pb2 = pictureBox2;
|
88
|
+
|
89
|
+
pb3 = pictureBox3;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
private void File_Open_Click(object sender, EventArgs e)
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
Image im1 = Image.FromFile(openFileDialog1.FileName);
|
106
|
+
|
107
|
+
DrawPicture1(im1);
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
private void DrawPicture1(Image im1)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
double a;
|
122
|
+
|
123
|
+
int maxsize = 200;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
if (im1.Width < maxsize && im1.Height < maxsize)
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
pb1.Width = pb1.Height = maxsize;
|
132
|
+
|
133
|
+
Rectangle rect1 = new Rectangle(0, 0, im1.Width, im1.Height);//イメージのサイズ
|
134
|
+
|
135
|
+
Rectangle rect2 = new Rectangle(0, 0, pb1.Width, pb1.Height);//PictureBox1のサイズ
|
136
|
+
|
137
|
+
bmp1_im1 = new Bitmap(pb1.Width, pb1.Height);
|
138
|
+
|
139
|
+
Graphics g = Graphics.FromImage(bmp1_im1);
|
140
|
+
|
141
|
+
g.DrawImage(im1, rect2, rect1, GraphicsUnit.Pixel);
|
142
|
+
|
143
|
+
g.Dispose();
|
144
|
+
|
145
|
+
pb1.Image = bmp1_im1;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
else
|
150
|
+
|
151
|
+
{
|
152
|
+
|
153
|
+
if (im1.Width > im1.Height)
|
154
|
+
|
155
|
+
{
|
156
|
+
|
157
|
+
/*a = (double)maxsize / (double)im1.Width;*/
|
158
|
+
|
159
|
+
pb1.Width = maxsize;
|
160
|
+
|
161
|
+
pb1.Height = maxsize /* (int)(a * im1.Height)*/;
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
else
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
/*a = (double)maxsize / (double)im1.Height;*/
|
170
|
+
|
171
|
+
pb1.Height = maxsize;
|
172
|
+
|
173
|
+
pb1.Width =maxsize /*(int)(a * im1.Width)*/;
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
Rectangle rect3 = new Rectangle(0, 0, im1.Width, im1.Height);//イメージのサイズ
|
178
|
+
|
179
|
+
Rectangle rect4 = new Rectangle(0, 0, pb1.Width, pb1.Height);//PictureBox1のサイズ
|
180
|
+
|
181
|
+
bmp1_im1 = new Bitmap(pb1.Width, pb1.Height);
|
182
|
+
|
183
|
+
Graphics g = Graphics.FromImage(bmp1_im1);
|
184
|
+
|
185
|
+
g.DrawImage(im1, rect4, rect3, GraphicsUnit.Pixel);
|
186
|
+
|
187
|
+
g.Dispose();
|
188
|
+
|
189
|
+
pb1.Image = bmp1_im1;
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
private void File_SaveBMP_Click(object sender, EventArgs e)
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
pb2.Image.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
private void P_GrayScale_Click(object sender, EventArgs e)
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
int i, j, nx, ny;
|
218
|
+
|
219
|
+
int gray;
|
220
|
+
|
221
|
+
Color col;
|
222
|
+
|
223
|
+
nx = pb3.Width;
|
224
|
+
|
225
|
+
ny = pb3.Height;
|
226
|
+
|
227
|
+
bmp1_im2 = new Bitmap (pb3.Image);
|
228
|
+
|
229
|
+
for (j = 0; j < ny; j++)
|
230
|
+
|
231
|
+
for (i = 0; i < nx; i++)
|
232
|
+
|
233
|
+
{
|
234
|
+
|
235
|
+
col = bmp1_im2.GetPixel(i, j);
|
236
|
+
|
237
|
+
if (col.R > 200 && col.B > 200 && col.G > 200) gray = 255;
|
238
|
+
|
239
|
+
else gray = 0;
|
240
|
+
|
241
|
+
bmp1_im2.SetPixel(i, j, Color.FromArgb(gray, gray, gray));
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
pb2.Image = bmp1_im2;
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
private void gausian_Click(object sender, EventArgs e)
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
int nx, ny;
|
256
|
+
|
257
|
+
int gray;
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
nx = pb1.Width;
|
262
|
+
|
263
|
+
ny = pb1.Height;
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
// 画像の読み込み(グレースケールに変換)
|
268
|
+
|
269
|
+
bmp1_im3 = new Bitmap(pb1.Image);
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
// フィルタ用のカーネル
|
274
|
+
|
275
|
+
const int kernelSize = 3; // カーネルサイズ
|
276
|
+
|
277
|
+
double[,] kernel = new double[kernelSize, kernelSize]{
|
278
|
+
|
279
|
+
{1/16.0, 1/8.0, 1/16.0},
|
280
|
+
|
281
|
+
{1/8.0, 1/4.0, 1/8.0},
|
282
|
+
|
283
|
+
{1/16.0, 1/8.0, 1/16.0}};
|
284
|
+
|
285
|
+
/* フィルタ処理
|
286
|
+
|
287
|
+
bmp1_im3 = Filter(pb3.Image, kernel); ←ここの部分です
|
288
|
+
|
289
|
+
*/
|
290
|
+
|
291
|
+
pb3.Image = bmp1_im3;
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
```
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
### 試したこと
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
'Filter'の定義をしないとだめだと思い、試しましたがエラーがでるだけで、使用できませんでした。フィルタ処理の知識がないプログラム初心者ですみません。
|
288
310
|
|
289
311
|
|
290
312
|
|
@@ -292,6 +314,6 @@
|
|
292
314
|
|
293
315
|
|
294
316
|
|
295
|
-
|
317
|
+
大学のPCで visual studio 2005でコードを書いています。
|
296
|
-
|
318
|
+
|
297
|
-
|
319
|
+
※詳しいデザイン画面を貼るので少しおまちください。
|