Converting Magick::Image to MagickLib::Image?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
stuartwhelan

Converting Magick::Image to MagickLib::Image?

Post by stuartwhelan »

I have seen this asked a few times in the forum, but no answer was every given that I can find...

How do you convert from a Magick::Image to a MagickLib::Image so you can do something like this?

Code: Select all


#define MAGICKCORE_IMPLEMENTATION 1
#include <Magick++.h>
using namespace Magick;


int main()
{
   Image imagea;
   Image imageb;

   imagea.read("pic.png");
   imageb.read("pic2.png");
 
   double dist;
   MagickLib::Image *imagec = MagickLib::CompareImages((MagickLib::Image *)&imagea, (MagickLib::Image *) &imageb, MagickLib::MeanSquaredErrorMetric, &dist, NULL);
   printf("%f\n", dist);
  return 0;
}
stuartwhelan

Re: Converting Magick::Image to MagickLib::Image?

Post by stuartwhelan »

I obviously didn't search enough.. Sorry.

Code: Select all

   Image imagea;
   Image imageb;
   imagea.read("pic.png");
   imageb.read("pic2.png");

   double dist;
   ExceptionInfo *exception;
   exception = MagickLib::AcquireExceptionInfo();
   MagickLib::Image *imagec = MagickLib::CompareImages(imagea.image(), imageb.image(), MagickLib::MeanSquaredErrorMetric, &dist, exception);
   printf("%f\n", dist);
   Image c(imagec);
   c.display();
stuartwhelan

Re: Converting Magick::Image to MagickLib::Image?

Post by stuartwhelan »

Just for completeness, and because I filled my memory, blew out my swap and up my filesystem with temp files, do not forget to free the image memory allocated in the bowels of CompareImages.

If you suddenly find you have hundreds of magick-* files in your temp dir, not freeing the cloned image could be the reason.

Code: Select all

   MagickLib::Image *imagec = MagickLib::CompareImages(imagea.image(), imageb.image(), MagickLib::MeanSquaredErrorMetric, &dist, exception);
   printf("%f\n", dist);
   Image c(imagec);
   c.display();
   MagickLib::DestroyImage(imagec);
Post Reply