Page 1 of 1

Converting Magick::Image to MagickLib::Image?

Posted: 2009-04-14T20:43:44-07:00
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;
}

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

Posted: 2009-04-14T21:08:05-07:00
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();

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

Posted: 2009-04-15T19:51:45-07:00
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);