This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This pattern comes handy when you want to add some annotation onto a series of images using familiar MatLab plot tools instead of having to modify the raster image directly.
In a recent 16-720 homework assignment, we were asked to implement then improve upon a baseline algorithm for scene classification, one step of which involves randomly sampling a given number of pixels from an image. The sample size is set to be far less than image size in order to save memory. While baseline method uses uniform sampling, I figured out that this has the undesirable property of creating clusters of samples in some areas of the image while totally ignoring some other areas. One possible improvement is to use so-called blue-noise sampling, where samples are not i.i.d.. Poisson Disk Sampling is a particular method which limits the euclidean distance between any pair of sampled points to be greater than a given minimum distance $r$.
Algorithm
I adapted an online demo by Jason Davies, which in turn uses a linear time algorithm by Robert Bridson. Since the sample size is given but poisson disk sampling expects only minimum distance, I used a heruistic to compute minimum distance from sample size: We can treat the distance constraint as circle packing problem, with radius of circles equal to 1/2 of minimum distance. If the circles are packed as tight as possible, the ratio of total area of circles to area of the rectangle is $\frac{\pi}{2\sqrt{3}}$. Using this relationship we could calculate the minimum distance:
$$ r = 2\sqrt{\frac{x y}{2\sqrt{3}}} $$
Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters