I've found a lot of documentation online about using ImageMagick's command line functions to create images of random noise, but have not been able to figure out how to reproduce that in Magick++.
ImageMagick has the +noise method Random:
convert -size 100x100 xc: +noise Random random.png
I would like to be able to set a pixel to Color("random"), for example:
sought.extent(Geometry(640,416), Color("random"), CenterGravity);
To embed a smaller image in a canvas of random noise. Of course, random isn't an acceptable argument for Color, but I'm wondering if the equivalent exists? The ideal would be if it were also possible to limit the range of colors - for example only 12-bit (#000-#FFF).
The method
Magick::Image::addNoise()
is a good place to start, but if you really want random/random. Use-fx "rand()"
.Edited by Mark Setchell
Much as I dislike editing other people's posts, I wanted to add something that is too big for a comment and not a competing answer, so this is the only way I know. Please feel free to ignore/delete/dissociate from this part!
If OP wants numbers corresponding to 12-bit values, I did a little experiment at the commandline like this to see how I could force that:
That generates a 1000 pixel image and forces the output to be an uncompressed PGM file that you can see the values in. I then sort them to see what the biggest value generated is, and it is 4096. So, I think the
-fx
expression I am suggesting ((rand*4096)/quantumrange
) may help generate 12-bit values.Additional Update
For mapping a region with random colors, an FX expression may look something like...
The
i
&j
or x/y offsets, and theu
is a the original image. A fun options, but traversing all the pixels will be slow. A faster option would be to create a random color image instance and useMagick::Image.composite
to place the image on top of another.