将CLI ImageMagick转换为Magick ++:阈值和深度 [英] Translate CLI ImageMagick to Magick++: threshold and depth
问题描述
我正在将代码中的 system
调用转换为 Magick ++
,但是在转换 threshold
和 depth时遇到了一些麻烦
.
I am converting a system
call to Magick++
in my code, but I am having some trouble converting the threshold
and depth
.
原件:
convert /foo/bar.ppm -crop WxH+X+Y -threshold 50% -depth 1 /foo/out.ppm
我当前的 C ++
版本是:
Magick::InitializeMagick(*argv);
Magick::Image img;
img.read("/foo/bar.ppm");
Magick::Image temp_img(img);
temp_img.chop(Magick::Geometry(X,Y);
temp_img.crop(Magick::Geometry(W,H));
temp_img.threshold(.50);
temp_img.depth(1);
temp_img.write("/foo/out.ppm");
chop
和 crop
的行为与我预期的一样,但其余部分则不然. threshold
和 depth
命令分别采用 double
和 size_t
.所以我在那写的东西似乎可以用.但是,如果启用这些行中的任何一条,结果图像几乎全部变成白色.
The chop
and crop
behaves like I expect, but the rest does not. The threshold
and depth
commands take a double
and a size_t
, respectively. So what I have written in there seems like it would work. However, if either one of these lines are enabled, the result image comes out nearly all white.
是否有更正确的方法?
推荐答案
Mark Setchell的评论正确. Maigck :: Image.threshold
的参数必须由QuantumRange缩放(由C宏定义提供).
Mark Setchell's comment is correct. Maigck::Image.threshold
's argument must be scaled by the QuantumRange (provided by a C macro definition).
temp_img.threshold(QuantumRange * 0.5);
对于大多数百分比百分比的参数,都希望采用这种缩放比例.
This scaling is expected for most arguments that are a percent ratio.
这篇关于将CLI ImageMagick转换为Magick ++:阈值和深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!