I need a truly random BMP in order to test various lossy image compression algorithms. Ideally, this would not rely on any library and run in a Linux CLI.
It should generate a random BMP given a certain width
and height
.
Updated Answer - April 2021
Here are some more ideas for random images:
Random coloured squares
magick -size 8x8 xc: +noise Random -scale 100x100 RandomColouredSquares.png
Random black and white crosswords
magick -size 8x8 xc:gray +noise Random -threshold 50% -scale 100x100 RandomCrosswords.png
Random grey blur
magick -size 8x8 xc:gray +noise Random -resize 100x100 RandomGreyBlur.png
Random coloured blur
magick -size 5x5 xc: +noise Random -auto-level -resize 100x100 RandomColouredBlur.png
Random salt and pepper
magick -size 100x100 xc:gray +noise Random -threshold 1% -negate RandomSaltAndPepper.png
Repeated coloured pattern
magick -size 50x50 xc: +noise random -virtual-pixel tile -blur 0x6 -auto-level -write MPR:tile +delete -size 250x250 tile:MPR:tile RandomRepeatedPattern.png
Updated Answer - March 2021
If you want random-noise type of images, see original answer below, noting that you should replace convert
with magick
in those examples if working with ImageMagick v7 onwards.
If you want images of a solid random colour, you could do something like this:
magick -size 400x200 xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))" image.png
Sample Outputs
If you want images of a random size and a random solid colour, you could use this for images between 200..264 pixels wide by 100..132 pixels tall:
magick -size "$(((RANDOM%64)+200))x$(((RANDOM%32)+100))" xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))"random.png
Sample Outputs
Original Answer
You can use ImageMagick
(which is installed on most Linux distros by default) to generate an image of random noise like this:
convert -size 300x200 xc:gray +noise random out.bmp
where 300
is the width and 200
is the height (just examples).
Other types of noise are available, just run
convert -list noise
Output
Gaussian
Impulse
Laplacian
Multiplicative
Poisson
Random
Uniform
If the noise is too noisy ;-) for you, you can attenuate it with
convert -size 300x200 xc:gray -attenuate 0.5 +noise random out.bmp
for a 50% attenuation
Here are some examples of the different types:
Here are the corresponding distribution histograms:
Just for completeness, note that this answer features in Daniel Barrett's book "Efficient Linux at the Command Line".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With