0
votes

I'm trying to get minima in image with Magick++ API version 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");

For several images I get the same minima value and a wrong value > 1.0.
Running identify -verbose on written image gives me correct value.

How can I solve this?

EDIT 1

If I do

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

I get the correct value for minima (and it is not in range 0 - 1.0 in ImageMagick 7).

img here is the result of

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

where mask is

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;
1

1 Answers

0
votes

Remember you are working with Quantum values -- which differ between system installs.

Use either value/QuantumRange or value*QuantumScale to calculate the display value between 0 & 1.0.

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

For example...

// 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;
}

Compile & execute...

 $ ./sample_program
 => 0.14478

Compare with CLI application

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

Slight rounding, but that's expected with std:cout.