在 CLI 中生成随机 BMP

Generate random BMP in CLI

我需要一个真正随机的 BMP 来测试各种有损图像压缩算法。理想情况下,这不会依赖任何库和 Linux CLI 中的 运行。

它应该在给定 widthheight 的情况下生成随机 BMP。

更新答案 - 2021 年 4 月

这里有一些关于随机图片的更多想法:


随机彩色方块

magick -size 8x8 xc: +noise Random -scale 100x100 RandomColouredSquares.png


随机黑白填字游戏

magick -size 8x8 xc:gray +noise Random -threshold 50% -scale 100x100 RandomCrosswords.png


随机灰色模糊

magick -size 8x8 xc:gray +noise Random -resize 100x100 RandomGreyBlur.png


随机彩色模糊

magick -size 5x5 xc: +noise Random -auto-level -resize 100x100 RandomColouredBlur.png


随机盐和胡椒粉

magick -size 100x100 xc:gray +noise Random -threshold 1% -negate RandomSaltAndPepper.png


重复彩色图案

magick -size 50x50 xc: +noise random -virtual-pixel tile -blur 0x6 -auto-level -write MPR:tile +delete -size 250x250 tile:MPR:tile RandomRepeatedPattern.png

更新答案 - 2021 年 3 月

如果你想要随机噪声类型的图像,请参阅下面的原始答案,注意如果使用 ImageMagick[=,你应该将这些示例中的 convert 替换为 magick 123=] v7 以后。

如果您想要纯随机颜色的图像,您可以这样做:

magick -size 400x200 xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))" image.png

示例输出


如果您想要随机大小和随机纯色的图像,您可以将其用于 200..264 像素宽 x 100..132 像素高的图像:

magick -size "$(((RANDOM%64)+200))x$(((RANDOM%32)+100))" xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))"random.png

示例输出

原答案

您可以使用 ImageMagick(默认情况下安装在大多数 Linux 发行版上)来生成像这样的随机噪声图像:

convert -size 300x200 xc:gray +noise random out.bmp

其中 300 是宽度,200 是高度(仅示例)。

其他类型的噪音可用,只是运行

convert -list noise

输出

Gaussian
Impulse
Laplacian
Multiplicative
Poisson
Random
Uniform

如果噪音太大 ;-) 对你来说,你可以用

减弱它
convert -size 300x200 xc:gray -attenuate 0.5 +noise random out.bmp

衰减 50%

以下是不同类型的一些示例:

对应的分布直方图如下: