我有很多未排序的2D点,它们代表图像中随机选取的像素的位置。在下一步中,我尝试按2x数组中的x,y值最小的点对它们进行排序/栅格化数组[0] [0]和具有最高x,y值的点在数组[n] [k]
条件1:所有其他2D都应在此边界之间并且几乎已排序。
条件2:数组的所有行应几乎填充相同数量的值,对于列也应相同。
任何想法如何解决此问题?
我计算了关于伏洛诺伊图的delaunay三角剖分和思想,以便一步一步地将每个单元格都扔了,但是我不知道我是否在正确的路径上。
我的随机位置是通过这种方式创建的:
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点,它们代表图像中随机选取的像素的位置。在下一步中,我尝试按2x数组中的x,y值在...
使用以下代码,您可以生成带有随机像素的“二维数组”。我认为没有必要使用类似sample_rand_points
的生成器函数。