如何在 ImageMagick 中指定自定义通道分布?
我有一堆文件,它们不是 RGB16,但本质上有自定义格式。
该格式有 16 位,通道划分如下,我希望 ImageMagick 如此导入它们,然后将它们导出为可读的常规 RGBA 格式(或者将每个通道导出到单独的灰度文件中)。
位 0-4:红色
位 5-9:绿色
位 10-12:蓝色
位 13-15:Alpha
所以本质上是 5-5-3-3。
这里是一个压缩的示例文件,即所需的输出(PNG 格式)也包括在内。 有谁知道该怎么做?
我以不同的手动方式成功地做到了这一点,但我不知道如何在 ImageMagick 中做到这一点。
I've got a bunch of files that are not e. g. RGB16 but essentially have a custom format.
This format has 16 bits, and the channels are divided as follows, and I want ImageMagick to import them as such and then export them to a readable, regular RGBA format (or alternatively, export each channel into a seperate grayscale file).
Bit 0-4: Red
Bit 5-9: Green
Bit 10-12: Blue
Bit 13-15: Alpha
So essentially 5-5-3-3.
Here is a zipped sample file, the wanted output (in PNG) is also included.
Does anyone know how to do that?
I succeeded in doing this in a different, manual way, but I have no idea how to do this in ImageMagick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先要做的就是获取您提供的预期输出,并将其分离为其组成的 RGBA 通道,并将它们并排放置,以便我们可以看到每个通道的目标:
接下来要做的就是检查文件大小。你说的是 512x512 像素的 16 位数据。这意味着我期望 512x512x2,即 524,288 字节,但您的文件有 524,290 字节。快速检查显示开头有一个 2 字节的 BOM 我们需要跳过。这意味着我们的命令必须将数据视为 512x512 像素的 16 位灰度数据,并带有要跳过的 2 字节标头。我们也不想读取该文件 4 次,因此我们将其放入 MPR “Magick 持久寄存器”(或“命名内存块” 我是这样认为的)并在每次解码通道时调用原始数据。
因此,在下面的命令中,第一行读取输入图像,跳过 BOM 并将其放入 MPR 中。第二行获取 MPR 的副本,并对其中的红色通道进行位旋转。第二、第三和第四行对绿色、蓝色和 Alpha 通道执行相同的操作。最后一行将处理堆栈中的 4 个通道合并到输出文件中。
注意:
在我不使用也无法测试的 Windows 上,该命令将如下所示:
只是为了好玩,您可以在 Python 中执行相同的操作:
The first thing to do is take the expected output you kindly provided and separate that into its constituent RGBA channels and lay them out side-by-side so we can see what we are aiming for in each channel:
Next thing is to check the file size. You said 512x512 pixels of 16-bit data. That means I am expecting 512x512x2, i.e. 524,288 bytes but your file has 524,290 bytes. A quick examination shows you have a 2-byte BOM at the start that we need to skip over. That means our command must treat the data as 512x512 pixels of 16-bit greyscale data with a 2-byte header to skip. We also do not want to read the file 4 times, so we put it into an MPR "Magick Persistent Register" (or "lump of named memory" is how I think of it) and recall the original data from there each time as we decode the channels.
So, in the command below, the first line reads the input image, skipping the BOM and puts it into the MPR. The second line takes a copy of the MPR and bit-twiddles the Red channel out of it. The second, third and fourth lines do the same for the Green, Blue and Alpha channels. The final line combines the 4 channels in the processing stack into the output file.
Note:
On Windows, which I don't use and cannot test, that command will look something like this:
Just for fun, you can do the same thing in Python: