We don't bite newbies here... much PerlMonks

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

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

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

Create A New User
Node Status?
node history
Node Type: note [id://1066431]
help
Chatterbox?
What's the matter? Cat got your tongue?...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2018-03-17 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (225 votes). Check out past polls.

Notices?