【问题标题】:Statistics with Magick++ ImageMagick 7.0.5-4 Q16 x86_64 issueMagick++ ImageMagick 7.0.5-4 Q16 x86_64 问题的统计信息
【发布时间】:2017-04-11 22:01:15
【问题描述】:

我正在尝试使用 Magick++ API 版本 7 获得图像中的最小值:

img.type(Magick::GrayscaleType);

auto stats = img.statistics();

std::cout << argv[0] << ":" << stats.channel(Magick::PixelChannel::GrayPixelChannel ).minima() << std::endl;

img.write("test" + Glib::ustring(argv[0]) + ".bmp");

对于几张图像,我得到相同的 minima 值和错误值 > 1.0。
在书面图像上运行 identify -verbose 给了我正确的值。

我该如何解决这个问题?

编辑 1

如果我这样做了

img.read("test" + Glib::ustring(argv[0]) + ".bmp");
stats = img.statistics();
std::cout << argv[0] << ":" << stats.channel(Magick::PixelChannel::GrayPixelChannel ).minima() << std::endl;

我得到了正确的最小值(在 ImageMagick 7 中它不在 0 - 1.0 的范围内)。

这里的img是

的结果
img.composite(mask, 0, 0, Magick::OverCompositeOp);

掩码在哪里

Magick::Image newmask(Magick::Geometry(width,height),Magick::Color("white"));
    newmask.strokeColor("black");
    newmask.fillColor("black");
    newmask.draw( Magick::DrawableCircle(xc,yc, xc,yc+rc-10) );
    newmask.transparent(Magick::Color("black"));
    newmask.depth(8);
    mask = newmask;

【问题讨论】:

    标签: c++ imagemagick magick++


    【解决方案1】:

    请记住,您使用的是 Quantum 值——这在系统安装之间会有所不同。

    使用value/QuantumRangevalue*QuantumScale 计算01.0 之间的显示值。

    stats.channel(Magick::PixelChannel::GrayPixelChannel).minima()/QuantumRange
    

    例如...

    // sample_program.cpp
    #include <iostream>
    #include <Magick++.h>
    
    using namespace std;
    using namespace Magick;
    
    int main(int argc, const char * argv[]) {
        InitializeMagick(argv[0]);
        Image img("rose:");
        img.type(GrayscaleType);
        auto stats = img.statistics();
        cout << stats.channel(PixelChannel::GrayPixelChannel).minima()/QuantumRange << endl;
        return 0;
    }
    

    编译并执行...

     $ ./sample_program
     => 0.14478
    

    与 CLI 应用程序比较

     $ convert rose: -type GrayScale -format '%[fx:minima]\n' info:
     => 0.144778
    

    略微四舍五入,但这是 std:cout 的预期结果。

    【讨论】:

    • 为什么不同:convert rose: -colorspace Gray bmp:- | identify -verbose - | grep min min: 37 (0.145098)
    • 因为数据人群不同。每次您在内存中或通过编码操作图像时,统计值都会改变。在您评论的示例中,您生成了一个 BMP 8 位 sRGB 图像,并且观察到了一些精度损失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 2016-03-22
    • 2021-02-15
    相关资源
    最近更新 更多