Image 在CLI中生成随机BMP

Image 在CLI中生成随机BMP,image,random,command-line-interface,Image,Random,Command Line Interface,我需要一个真正随机的BMP来测试各种有损图像压缩算法。理想情况下,这将不依赖于任何库并在Linux CLI中运行 给定一定的宽度和高度更新答案,应生成一个随机BMP-2021年4月 以下是一些关于随机图像的更多想法: 随机彩色方块 magick -size 8x8 xc: +noise Random -scale 100x100 RandomColouredSquares.png 随机黑白纵横字谜 magick -size 8x8 xc:gray +noise Random -thres

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


给定一定的
宽度
高度

更新答案,应生成一个随机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月

如果您想要随机噪声类型的图像,请参见下面的原始答案,注意如果使用ImageMagickv7以后的版本,在这些示例中,您应该将
convert
替换为
magick

如果您想要纯色随机颜色的图像,可以执行以下操作:

magick -size 400x200 xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))" image.png
convert -size 300x200 xc:gray +noise random out.bmp
样本输出


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

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

原始答案

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

magick -size 400x200 xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))" image.png
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%

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

以下是相应的分布直方图:


如果您想要彩色或透明图像,请使用
xc:wheat
或其他类似选项,如
卡其色、透明、无等。convert 1.bmp-colorspace Gray-define histogram:unique colors=假直方图:1h.bmp