(1)这N个点要在图像边缘上;
(2)最近邻的两点之间要尽量分散开。
如,图像为:
需要设计一个采样算法,使它得到下面的结果:
==== 实现 ====
1,将图像加载,转换为ImageU8类(参见《发布我的高性能纯C#图像处理基本类,顺便也挑战一下极限。:)》),方便下一步处理。
2,获得全部边缘像素的位置。
在《重新认识C#: 玩转指针》的一文基础上新添加一个扩展方法:
1 public unsafe delegate void ActionOnPosition(Int32 x, Int32 y, TPixel* p);
2 public unsafe static void ForEach(this UnmanagedImage<TPixel> src, ActionOnPosition handler)
3 {
4 Int32 width = src.Width;
5 Int32 height = src.Height;
6
7 TPixel* p = (TPixel*)src.StartIntPtr;
8 for (Int32 r = 0; r < height; r++)
9 {
10 for (Int32 w = 0; w < width; w++)
11 {
12 handler(w, r, p);
13 p++;
14 }
15 }
16 }
2 public unsafe static void ForEach(this UnmanagedImage<TPixel> src, ActionOnPosition handler)
3 {
4 Int32 width = src.Width;
5 Int32 height = src.Height;
6
7 TPixel* p = (TPixel*)src.StartIntPtr;
8 for (Int32 r = 0; r < height; r++)
9 {
10 for (Int32 w = 0; w < width; w++)
11 {
12 handler(w, r, p);
13 p++;
14 }
15 }
16 }