Page 1 of 1

Composite Function for difference btw images

Posted: 2006-09-23T00:54:31-07:00
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

Posted: 2006-09-23T00:57:26-07:00
by anthony
Make a clone of the original (backframe) image first.

Thanks - and still stuck

Posted: 2006-09-23T02:39:46-07:00
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

Posted: 2006-09-23T18:52:00-07:00
by anthony
Now use the clone instead of the original for the composite.

Posted: 2006-09-24T22:13:17-07:00
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

Posted: 2006-09-24T22:28:58-07:00
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.

Posted: 2006-09-28T00:25:32-07:00
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

Posted: 2006-09-28T00:35:11-07:00
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++

Posted: 2006-09-28T00:46:38-07:00
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

Posted: 2006-09-28T01:02:36-07:00
by anthony
I'll have to leave this then. outside my expertise.

Posted: 2006-09-28T01:08:49-07:00
by Pranjal
Hmm...

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