Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Randomly biased, random numbers. (A working solution)

by salva (Monsignor)
on Dec 10, 2013 at 13:58 UTC ( #1066431=note: print w/ replies, xml ) Need Help??


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].


Comment on Re^5: Randomly biased, random numbers. (A working solution)
Select or Download Code
Re^6: Randomly biased, random numbers. (A working solution)
by BrowserUk (Pope) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-10-02 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (56 votes), past polls