Opening的算法是:先对图片做Erosion,将结果再做Dilation,其目的在消除影像中的小杂点。
1
#include "stdafx.h"
2
#include <vector>
3
#include <algorithm>
4
5
using namespace System::Drawing;
6
using namespace System::Drawing::Imaging;
7
8
typedef std::pair<int, int> MyPoint;
9
typedef std::vector<MyPoint> MyPointVec;
10
typedef int GrayLevel;
11
12
// Make kernel by radius
13
MyPointVec makeKernel(const int&);
14
// Process opening
15
Bitmap^ opening(Bitmap^, const MyPointVec%);
16
// Process dilation
17
Bitmap^ dilation(Bitmap^, const MyPointVec%);
18
// Process erosion
19
Bitmap^ erosion(Bitmap^, const MyPointVec%);
20
// Get max gray level by kernel
21
GrayLevel getMaxByKernel(Bitmap^, const MyPointVec%, const MyPoint%);
22
// Get max gray level by kernel
23
GrayLevel getMinByKernel(Bitmap^, const MyPointVec%, const MyPoint%);
24
// Get gray level from Color object
25
GrayLevel getGrayLevelFromColor(Color^);
26
27
}
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
原图
执行结果
See Also
如何使用C++/CLI对图片做Grayscale Dilation?
如何使用C++/CLI对图片做Grayscale Erosion?
如何使用C++/CLI对图片做Grayscale Closing?