http://www.perlmonks.org?node_id=1066431


in reply to Re^4: Randomly biased, random numbers. (A working solution)
in thread Randomly biased, random numbers.

Use the color or luminance or hue of the images to weight the picking of 'random' pixels.

This is also quite hard to do other than via the rejection method

There is a much more efficient method. See here, and here.

The trick is to build an 1D array with the accumulated weights @acu. Then, pick random numbers ($r) in the range [0, $acu[-1]) and use binary search to look for the index $ix such that $acu[$ix] <= $r <= $acu[$ix + 1].

Replies are listed 'Best First'.
Re^6: Randomly biased, random numbers. (A working solution)
by BrowserUk (Patriarch) on Dec 10, 2013 at 14:32 UTC

    That's nice. I'll have to try it on a a random selection of images, but it is definitely interesting.

    (I'm a bit confused why you are writing back the current pixel with the same color you just read, and then setting the color of the adjacent pixel one row down to the newly calculated color? Which means you'll be re-reading your new values when processing the next row.

    And why x => $w + $i</x> rather than <c>y => $j + 1?)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      The output file contains three images side by side:
      • the original image at the left
      • the weights image in the middle
      • and the image with the random points at the right

        Ah! Makes sense now :) Thanks.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.