如何为您的空间定义一个任意分辨率,并为该矩阵中的每个点计算从该点到所有点的距离的度量,然后可以制作一个“热图”并使用阈值来定义聚类。
这是一个很好的处理过程,也许以后我会发布解决方案。
编辑:
这里是:
//load the imagePImage sample;sample = loadImage("test.png");size(sample.width, sample.height);image(sample, 0, 0);int[][] heat = new int[width][height];//parametersint resolution = 5; //distance between points in the gridqint distance = 8; //distance at wich two points are considered nearfloat threshold = 0.5;int level = 240; //leven to detect the dotsint sensitivity = 1; //how much does each dot matters//calculate the "heat" on each point of the gridcolor black = color(0,0,0);loadPixels();for(int a=0; a<width; a+=resolution){ for(int b=0; b<height; b+=resolution){ for(int x=0; x<width; x++){ for(int y=0; y<height; y++){ color c = sample.pixels[y*sample.width+x]; if(brightness(c)<level && dist(x,y,a,b)<distance){ heat[a][b] += sensitivity; } } } }}//render the outputfor(int a=0; a<width; ++a){ for(int b=0; b<height; ++b){ pixels[b*sample.width+a] = color(heat[a][b],0,0); }}updatePixels();filter(THRESHOLD,threshold);
编辑2(低效率代码少但输出相同):
//load the imagePImage sample;sample = loadImage("test.png");size(sample.width, sample.height);image(sample, 0, 0);int[][] heat = new int[width][height];int dotQ = 0;int[][] dots = new int[width*height][2];int X = 0;int Y = 1;//parametersint resolution = 1; //distance between points in the gridint distance = 20; //distance at wich two points are considered nearfloat threshold = 0.6;int level = 240; //minimum brightness to detect the dotsint sensitivity = 1; //how much does each dot matters//detect all dots in the sampleloadPixels();for(int x=0; x<width; x++){ for(int y=0; y<height; y++){ color c = pixels[y*sample.width+x]; if(brightness(c)<level) { dots[dotQ][X] += x; dots[dotQ++][Y] += y; } }}//calculate heatfor(int x=0; x<width; x+=resolution){ for(int y=0; y<height; y+=resolution){ for(int d=0; d<dotQ; d++){ if(dist(x,y,dots[d][X],dots[d][Y]) < distance) heat[x][y]+=sensitivity; } }}//render the outputfor(int a=0; a<width; ++a){ for(int b=0; b<height; ++b){ pixels[b*sample.width+a] = color(heat[a][b],0,0); }}updatePixels();filter(THRESHOLD,threshold);
和带有(减少的)Kent样本的输出:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)