Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How about defining an arbitrary resolution for your space, and calculate for each point in that matrix, a measure of the distance from that point to all dots, then you could make a "heat graph" and use a threshold to define the clusters.</p> <p>It's a nice exercise for processing, maybe later I will post a solution.</p> <p>EDIT:</p> <p>Here it is:</p> <pre><code>//load the image PImage sample; sample = loadImage("test.png"); size(sample.width, sample.height); image(sample, 0, 0); int[][] heat = new int[width][height]; //parameters int resolution = 5; //distance between points in the gridq int distance = 8; //distance at wich two points are considered near float threshold = 0.5; int level = 240; //leven to detect the dots int sensitivity = 1; //how much does each dot matters //calculate the "heat" on each point of the grid color black = color(0,0,0); loadPixels(); for(int a=0; a&lt;width; a+=resolution){ for(int b=0; b&lt;height; b+=resolution){ for(int x=0; x&lt;width; x++){ for(int y=0; y&lt;height; y++){ color c = sample.pixels[y*sample.width+x]; /** * the heat should be a function of the brightness and the distance, * but this works (tm) */ if(brightness(c)&lt;level &amp;&amp; dist(x,y,a,b)&lt;distance){ heat[a][b] += sensitivity; } } } } } //render the output for(int a=0; a&lt;width; ++a){ for(int b=0; b&lt;height; ++b){ pixels[b*sample.width+a] = color(heat[a][b],0,0); } } updatePixels(); filter(THRESHOLD,threshold); </code></pre> <p>EDIT 2 (slighly less inefficient code but same output): </p> <pre><code>//load the image PImage 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; //parameters int resolution = 1; //distance between points in the grid int distance = 20; //distance at wich two points are considered near float threshold = 0.6; int level = 240; //minimum brightness to detect the dots int sensitivity = 1; //how much does each dot matters //detect all dots in the sample loadPixels(); for(int x=0; x&lt;width; x++){ for(int y=0; y&lt;height; y++){ color c = pixels[y*sample.width+x]; if(brightness(c)&lt;level) { dots[dotQ][X] += x; dots[dotQ++][Y] += y; } } } //calculate heat for(int x=0; x&lt;width; x+=resolution){ for(int y=0; y&lt;height; y+=resolution){ for(int d=0; d&lt;dotQ; d++){ if(dist(x,y,dots[d][X],dots[d][Y]) &lt; distance) heat[x][y]+=sensitivity; } } } //render the output for(int a=0; a&lt;width; ++a){ for(int b=0; b&lt;height; ++b){ pixels[b*sample.width+a] = color(heat[a][b],0,0); } } updatePixels(); filter(THRESHOLD,threshold); /** This smooths the ouput with low resolutions * for(int i=0; i&lt;10; ++i) filter(DILATE); * for(int i=0; i&lt;3; ++i) filter(BLUR); * filter(THRESHOLD); */ </code></pre> <p>And the output with (a reduced) Kent sample:</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload