[英]Magick++ blur mask
I am trying to convert an ImageMagick command for a blurring mask to Magick++ API. 我正在尝试将用于模糊蒙版的ImageMagick命令转换为Magick ++ API。
ImageMagick : ImageMagick :
convert -size 720x478 xc: -sparse-color Barycentric '0,0 black 0,%h white' -function polynomial 4,-4,1 -level 0,50% mask.jpg
Magick++ : Magick ++ :
Magick::Image mask(Magick::Geometry(720,478), Magick::Color("white"));
double args[6];
args[0] = 0;
args[1] = 0;
args[2] = 0;
args[3] = 0;
args[4] = mask.rows();
args[5] = MaxRGB;
mask.sparseColor(Magick::DefaultChannels, Magick::BarycentricColorInterpolate, 6, args);
args[0] = 4;
args[1] = -4;
args[2] = 1;
args[3] = 0;
args[4] = 0;
args[5] = 0;
mask.quantumOperator(Magick::DefaultChannels, Magick::PolynomialFunction,
3,args);
parseLevel(image, "0,50%", args); // contains code from mogrify.c for parsing the leveling string
mask.level(args[0], args[1], args[2], ' ');
The result I get is just a white image, whereas the correct mask image should be like this: 我得到的结果只是一个白色图像,而正确的蒙版图像应如下所示:
Can someone please show me my mistake? 有人可以告诉我我的错误吗?
Mhm, I have no experience with imagemagick, but quickly looking into the docs and at your example, I have a hunch: Maybe the default image type is rgb, and you need three float/double parameters for each color in your sparse-color call. 嗯,我没有使用imagemagick的经验,但是快速查看文档,在您的示例中,我有一个直觉:也许默认的图像类型是rgb,并且在稀疏颜色调用中每种颜色都需要三个float / double参数。 Like that: 像那样:
Magick::Image mask(Magick::Geometry(720,478), Magick::Color("white"));
double args[10];
// -sparse-color Barycentric '0,0 black 0,%h white'
args[0] = 0; // x = 0
args[1] = 0; // y = 0
args[2] = 0; // black (R)
args[3] = 0; // black (G)
args[4] = 0; // black (B)
args[5] = 0; // x = 0
args[6] = mask.rows(); // y = %h
args[7] = MaxRGB; // white (R)
args[8] = MaxRGB; // white (G)
args[9] = MaxRGB; // white (B)
mask.sparseColor(Magick::DefaultChannels, Magick::BarycentricColorInterpolate, 10, args);
So it turns out that I was giving the wrong ChannelType
in sparseColor()
function. 所以,事实证明,我给了错误的ChannelType
在sparseColor()
函数。 The DefaultChannels
enum contains RGBChannels
with OpacityChannel
and IndexChannel
. 该DefaultChannels
枚举包含RGBChannels
与OpacityChannel
和IndexChannel
。 I had to exclude the latter two from the DefaultChannels enum by bitwise operation. 我必须通过按位操作将后两个从DefaultChannels枚举中排除。 As @ThorngardSO pointed out, the args size also needs to be 10. 正如@ThorngardSO所指出的,args的大小也需要为10。
code : 代码 :
double args[10];
// -sparse-color Barycentric '0,0 black 0,%h white'
args[0] = 0; // x = 0
args[1] = 0; // y = 0
args[2] = 0; // black (R)
args[3] = 0; // black (G)
args[4] = 0; // black (B)
args[5] = 0; // x = 0
args[6] = mask.rows(); // y = %h
args[7] = MaxRGB; // white (R)
args[8] = MaxRGB; // white (G)
args[9] = MaxRGB; // white (B)
mask.sparseColor((Magick::DefaultChannels & ~OpacityChannel) & ~IndexChannel, Magick::BarycentricColorInterpolate, 10, args);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.