mata mata - 3 months ago 33
C++ Question

Convert jpeg using gamma correction in c++

I have an image img.jpg and I want to convert it to newImg.jpg using the linear gamma correction. I found out how I can do it using the terminal:

convert img.jpg -gamma valueOfgamma newImg.jpg


But now I want to do it in my C++ program. How can I do that using imagemagick++ or openCv?

Thanks

Answer

With you would use method Magick::Image.gamma(const double).

#include <Magick++.h>

int main(int argc, const char * argv[]) {
    double valueOfgamma = 1.0;
    Magick::InitializeMagick(argv[0]);

    // convert img.jpg -gamma valueOfgamma newImg.jpg
    Magick::Image image("img.jpg");
    image.gamma(valueOfgamma);
    image.write("newImg.jpg");

    return 0;
}