How about calculating the density value for each pixel, starting with its proximity to all other pixels. Then repeatedly delete the “densest” pixel until you stay below p% remaining in the list.
You will need to do a distance calculation to determine the density between any two points no more than two times. The first time will be when you create the source list - each pixel will need to be compared with each other's pixel. Secondly, when you remove a pixel from the list, you will need to calculate the deleted file for each of the remaining in the list. This should take into account the change in density values when each pixel is deleted - for example, 2 pixels directly next to each other will have a very very high value, but as soon as one is deleted, the remaining one can have a very low value.
Some quick pseudo codes (note that in this example, areas with higher density have a small amount)
For I = 0 to MaxPixel For J = I to MaxPixel PixelDensity[I], PixelDensity[J] += DistanceBetween(Pixels[I], Pixels[J]) While PixelDensity.Count > TargetCount RemovePixel = IndexOfSmallest(PixelDensity) ForEach I in PixelDensity PixelDensity[I] -= DistanceBetween(Pixels[I], Pixels[RemovePixel]) PixelDensity.Remove(RemovePixel)
If memory is less of a concern than computation time, you can also save the distance between any two points in a simple 2d array. In addition, instead of a simple distance, it would be useful to make an exponential calculation of the distance - this will avoid something like two points located almost one above the other, but away from everything else and passing both.
matthock
source share