Subtract images - Bug or incompetence

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
Hasek1984

Subtract images - Bug or incompetence

Post by Hasek1984 »

Hello this is a short question regarding pixelcalculation in c/c++.

darkpic.composite(brightpic,0,0,MinusCompositeOp);

As you can see, I use the MinusCompositeOp operation, but tried also DifferenceOp and SubtractOp.
Usually it works but some pixels are calculated wrong.
Image A (value 2038) - Image B (value 2004) should be value 34!
But in the resulting Image there is the wrong value 65525. Bug?
Both images are 16-bit tif and I work with Windows Vista(64).
By the way...is there a possibility to avoid updating the current image (darkpic) but the other (brightpic)?.
Thank you in advance.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Subtract images - Bug or incompetence

Post by el_supremo »

By the way...is there a possibility to avoid updating the current image (darkpic) but the other (brightpic)?.
Wouldn't this work?

Code: Select all

brightpic.composite(darkpic,0,0,MinusCompositeOp);
Pete
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Subtract images - Bug or incompetence

Post by anthony »

As hinted by el_supremo, you probably have the images the wrong way around.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Hasek1984

Re: Subtract images - Bug or incompetence

Post by Hasek1984 »

Thank you for your replies.

My intention is to subtract a dark picture from a bright one (same object) due to remove the "dark-current" artefacts.

If I change the way of subtraction then the result is a complete dark picture.
Because dark picture - bright picture = dark picture (overflow cropped to zero).


Am I wrong with my assumption?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Subtract images - Bug or incompetence

Post by anthony »

You are wrong in your ordering.

You were subtracting the bright picture from the dark picture.
"Subtract" is a 'modulus' subtraction. If you used minus, you would have gotten all zeros.

Look at http://www.imagemagick.org/Usage/compose/tables/
and especially the gradient compose test results at the bottom.

I just updated this to include the Add and Subtract modulus compositions, which will appear in a day or so.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply