简体   繁体   English

如何用Magick ++编写这些`convert`命令?

[英]How to write these `convert` commands in Magick++?

I've decided on using Magick++ for my application. 我已经决定在我的应用程序中使用Magick ++。 I know which convert commands I want to use but I don't know how to translate them into Magick++ code. 我知道我想使用哪些convert命令,但是我不知道如何将其转换为Magick ++代码。

My application should quantize the colors in a imported image using a fixed hardcoded palette, with optional dithering (FD, Riemersma, Bayer, Halftone, Random). 我的应用程序应该使用固定的硬编码调色板以及可选的抖动(FD,Riemersma,Bayer,Halftone,Random)来量化导入图像中的颜色。 It then passes the output to some later code. 然后,它将输出传递给以后的代码。

Here are the commands that give me the results I want. 这是给我想要的结果的命令。 Each one is individual, which one "gets run" depends on user set flags. 每一个都是独立的,一个“开始运行”取决于用户设置的标志。
Also, palette.png will be a Image object generated on run and is not actually read from file. 另外, palette.png将是在运行时生成的Image对象,实际上不会从文件中读取。
Also, again, out.png will not be exported to file and will be instead be another Image object passed onto later code. 同样, out.png不会导出到文件,而是另一个传递给以后代码的Image对象。

convert in.png -dither FloydSteinberg -remap palette.png out.png
convert in.png -dither Riemersma -remap palette.png out.png

convert in.png -ordered-dither o2x2,2 -remap palette.png out.png
convert in.png -ordered-dither o2x2,3 -remap palette.png out.png
convert in.png -ordered-dither o2x2,4 -remap palette.png out.png
# etc.

convert in.png -ordered-dither o3x3,2 -remap palette.png out.png
# etc.

convert in.png -ordered-dither o4x4,2 -remap palette.png out.png
# etc.

convert in.png -ordered-dither o8x8,2 -remap palette.png out.png
# etc.

# etc. through all ordered dithers

convert in.png -random-threshold 0x100% -remap palette.png out.png
convert in.png -random-threshold 10x90% -remap palette.png out.png
convert in.png -random-threshold 25x75% -remap palette.png out.png
convert in.png -random-threshold 30x80% -remap palette.png out.png

For -dither operator, use Magick::Image.quantizeDitherMethod() method. 对于-dither运算符,请使用Magick::Image.quantizeDitherMethod()方法。

Magick::Image img("in.png");
img.quantizeDitherMethod(Magick::FloydSteinbergDitherMethod);   

For -remap operator, use Magick::Image.map() method. 对于-remap运算符,请使用Magick::Image.map()方法。

Magick::Image img("in.png");
// ...
Magick::Image remap("palette.png");
img.map(remap, true);

For -ordered-dither operator, use Magick::Image.orderedDither() method. 对于-ordered-dither运算符,请使用Magick::Image.orderedDither()方法。

Magick::Image img("in.png");
// ...
img.orderedDither("o3x3,2"); 

For -random-threshold operator, use Magick::Image.randomThreshold() method. 对于-random-threshold运算符,请使用Magick::Image.randomThreshold() -random-threshold Magick::Image.randomThreshold()方法。

Magick::Image img("in.png");
// ...
img.randomThreshold(0.3 * QuantumRange, 0.8 * QuantumRange);  

Checkout Image.h header file, and other Magick++'s source code files for reference. 检出Image.h头文件和其他Magick ++的源代码文件以供参考。 I believe the documentation / examples are slightly out of date, but the developer comments are clear. 我认为文档/示例有些过时,但是开发人员的评论很清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM