Composite Function for difference btw images

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
Pranjal

Composite Function for difference btw images

Post by Pranjal »

Hello all,

I was able to solve the difference problem using pixel level values in C++, but after Anthony mentioned use of composite command for the same, I've been trying to figure out how I could do that in C++. I've tried the following :

Code: Select all

 backframe.composite(inframe,0,0,DifferenceCompositeOp);
But this places the difference btw backframe and inframe over backframe. I was looking at getting just the difference into a new image. Is there a way around this?

Thanks
Pranjal
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Make a clone of the original (backframe) image first.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Pranjal

Thanks - and still stuck

Post by Pranjal »

Hi Anthony,

Thanks for that quick reply. Like you said, I tried making a clone of the backframe image. I was not able to do it using CloneImage(), so I instead copied the pixels of backframe into an image called cloneback. But how do I proceed from there?

Thanks again,
Pranjal
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Now use the clone instead of the original for the composite.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Pranjal

Post by Pranjal »

Hi again,

Sorry to keep returning wih the same question again. But after cloning and using the new image, I still seem to get the esults into this new image. All I want is the difference between two images and the results as a new image by itself. The composite function seems to overwrite on the exsisting image pixels. I'm doing something wrong, and am not able to figure what.

Please help.
Thanks,
Pranjal
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

the composite function will always overwrite the destination image, that is is job.
If you want to keep the original destination image, you have two choices, either make a clone of that image, or read/create that image again.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Pranjal

Post by Pranjal »

Hi again,

I've tried the following -

Code: Select all

      Image inframe;
      inframe.read("image1.jpg");
      inframe.type(GrayscaleType);
      Image incopy = inframe;
            
      inframe.display();
      inframe.composite(incopy,0,0,DifferenceCompositeOp);
      inframe.display();
The result shows the original "image1.jpg". I was hoping it would be a "blank" image as the difference is "0". If that's not what Composite does, could you please tell me what will.

Please help.

Thanks,
-Pranjal
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

That is not a clone. You need to call CloneImage

Something like...
incopy = CloneImage(inframe);

I can't be certain as I don't use Magick++
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Pranjal

Post by Pranjal »

Thanks for that quick reply. Looks like Magick++ doesn't recognize CloneImage(). I've even tried the following -

Code: Select all

      Image inframe;
      Image backframe;
      inframe.read("image1.jpg");
      backframe.read("background.jpg");
      
      inframe.quantizeColorSpace(GRAYColorspace);
      backframe.quantizeColorSpace(GRAYColorspace);
      inframe.quantizeColors(2);
      backframe.quantizeColors(2);
      inframe.quantizeDither(false);
      backframe.quantizeDither(false);

      inframe.display();
      backframe.display();
And nothing seems to change in the images.(??!!)

-Pranjal
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

I'll have to leave this then. outside my expertise.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Pranjal

Post by Pranjal »

Hmm...

That's not good news for me... :cry:
Post Reply