【发布时间】:2020-06-26 21:40:23
【问题描述】:
我有很多未排序的 2D 点,它们代表图像中随机选取的像素的位置。
在下一步中,我尝试在 2D 数组中对它们进行排序/光栅化,按 x、y 值最小的点
array[0][0]
和在
处具有最高 x,y 值的点array[n][k]
条件1:
所有其他 2D 都应在此边界之间并且几乎已排序。
条件2:
数组的所有行都应该填充几乎相同数量的值,列也一样。
任何想法如何解决这个问题?
我计算了 delaunay-triangulation 并考虑了一个 voronoi 图,用于逐步抛出每个单元格,但我不知道我是否走在正确的道路上。
我的随机位置就是这样创建的:
std::vector<Point_d> sample_rand_points(){
std::cout<<"sampling random points\n";
std::vector<Point_d> output_pattern;
//PREPARE:
std::vector<std::pair<int, int> > not_sampled_yet;
for(int x=0; x<_X; x++)
{
for(int y=0; y<_Y; y++)
{
not_sampled_yet.push_back(std::pair<int,int>(x,y));
}
}
//SAMPLING
Point_d pix;
for (int i=0; i<_Amount; i++)
{
//std::cout<<i<<"\n";
int n= rand()% not_sampled_yet.size();
pix.x= (double)not_sampled_yet[n].first;
pix.y= (double)not_sampled_yet[n].second;
not_sampled_yet[n]=not_sampled_yet.back();
not_sampled_yet.pop_back();
output_pattern.push_back(pix);
}
return output_pattern;
}
输出是一个向量,点为 {{x1,y1},{x2,y2},......}
【问题讨论】:
-
输入数据(2D点)是如何生成的?
-
我插入了一些随机函数的代码
-
乍一看,将 x 和 y 坐标存储在两个单独的
std::vector<double>中是有意义的。这样更容易找到最小值和最大值。 -
我选择了这种数据格式作为 delaunay 库的输入。一开始我是按照我现在插入的方式编写的。
-
随机选择的像素数量约为原始 Pixelammount 的 60-70%。最小值始终为 x= 0 或 y= 0 且最大值为高度和高度的点。
标签: c++ algorithm sorting pixel delaunay