我有一个带有 4 个波段的 PNG,但我只想要 1 个带有颜色表的波段。我尝试在 MS Paint 中将其另存为 256 色位图,结果成功了。
但我需要自动完成。我尝试了 ImageMagick:convert E8.png E8256.bmp
但它不起作用。
这就是原图:
ImageMagick 识别
:
E8.png PNG 8250x4090 8250x4090+0+0 8-bit sRGB 231KB 0.000u 0:00.000
gdalinfo:
Driver: PNG/Portable Network Graphics
Files: E8.png
Size is 8250, 4090
Coordinate System is `'
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 4090.0)
Upper Right ( 8250.0, 0.0)
Lower Right ( 8250.0, 4090.0)
Center ( 4125.0, 2045.0)
Band 1 Block=8250x1 Type=Byte, ColorInterp=Red
Mask Flags: PER_DATASET ALPHA
Band 2 Block=8250x1 Type=Byte, ColorInterp=Green
Mask Flags: PER_DATASET ALPHA
Band 3 Block=8250x1 Type=Byte, ColorInterp=Blue
Mask Flags: PER_DATASET ALPHA
Band 4 Block=8250x1 Type=Byte, ColorInterp=Alpha
我想要一张只有一个色带和一个颜色表的图片,所以我用 MS Paint 打开 E8.png 并将其保存为 256 色位图。结果:
ImageMagick 识别
:
E8256.bmp BMP3 8250x4090 8250x4090+0+0 8-bit sRGB 256c 33.75MB 0.265u 0:00.138
gdalinfo:
Driver: BMP/MS Windows Device Independent Bitmap
Files: E8256.bmp
Size is 8250, 4090
Coordinate System is `'
Origin = (-1890.000000000000000,1890.000000000000000)
Pixel Size = (3780.000000000000000,-3780.000000000000000)
Corner Coordinates:
Upper Left ( -1890.000, 1890.000)
Lower Left ( -1890.000,-15458310.000)
Upper Right (31183110.000, 1890.000)
Lower Right (31183110.000,-15458310.000)
Center (15590610.000,-7728210.000)
Band 1 Block=8250x1 Type=Byte, ColorInterp=Palette
Color Table (RGB with 256 entries)
0: 0,0,0,255
1: 128,0,0,255
...
255: 255,255,255,255
但是当我尝试转换 E8.png E8imagemagick.bmp
时,我得到:
ImageMagick 识别
:
E8imagemagick.bmp BMP 8250x4090 8250x4090+0+0 8-bit sRGB 135MB 0.406u 0:00.409
gdalinfo:
Driver: BMP/MS Windows Device Independent Bitmap
Files: E8imagemagick.bmp
Size is 8250, 4090
Coordinate System is `'
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 4090.0)
Upper Right ( 8250.0, 0.0)
Lower Right ( 8250.0, 4090.0)
Center ( 4125.0, 2045.0)
Band 1 Block=8250x1 Type=Byte, ColorInterp=Red
Band 2 Block=8250x1 Type=Byte, ColorInterp=Green
Band 3 Block=8250x1 Type=Byte, ColorInterp=Blue
编辑: 这里( uploaded.net -- Dropbox )是原始 PNG,这里( uploaded.net -- dropbox )是我使用 MS Paint 获得的 BMP。
最佳答案
也许这个命令:
convert E8.png -colors 256 E8-256colors.bmp
让你更接近你想要的吗?不过,这个位图有点大……(129 MB)。所以这个应该更小:
convert E8.png -type palette -colors 256 E8-palette-256colors.bmp
最后一个只有 16 MB。
您的标题说“任何格式”,所以 PNG 也可能符合要求?它创建的输出要小得多:
convert E8.png -type palette -colors 256 E8-palette-256colors.png
(现在的大小只有 122 kByte。)
您的原始图像仅包含 6 种颜色,您的新输出也是如此:
identify -format "%f: %k\\n" E8.png E8-palette-256colors.png
E8.png: 6
E8-palette-256colors.png: 6
或者
identify E8.png E8-palette-256colors.png
E8.png PNG 8250x4090 8250x4090+0+0 8-bit sRGB 231KB 0.000u 0:00.000
E8-palette-256colors.png[1] PNG 8250x4090 8250x4090+0+0 8-bit sRGB 6c 125KB 0.000u 0:00.000
关于imagemagick - 将具有 4 个波段的 PNG 转换为具有 1 个波段和颜色表的任何格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27639782/