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?".
I forgot to mention in my original post, though, that these images don't have to be 100% black; that was just an edge case I found. Do you have a solution for a case like this?:
Let me clarify what i mean by anything. If i was given current-frame.png and asked to circle any pixels that have changed since previous-frame.png, that is what the output would be.
I was basically looking for a way to emulate the compare command with convert in order to avoid writing a temporary image to disk before further processing.
Try my solution on other images before you settle it. I am not sure if -channel rgba is really letting -compose difference deal properly with the alpha channel.
Spent a bit of time to make a test image (below) and it looks like your most recent script does just as well as compare does. I just have to add threshold 0 at the very end for my own use-case since i end up multiplying this mask later on.
Turning on -channel rgba, I believe makes -compose difference also include the alpha channel. So you now have 4 independently computed difference channels. To get all the differences combined together (depending upon which approach you use as per snibgo's comments), I combine the images together by adding them all together. That means if all 4 channels are black (the same), you get black, but if any channel is not black (they are not the same), you get white. In IM 6 non-hdri, adding white to white produces white. That is values are clipped at white and no overflow or wrap around.
Yes, you should add -threshold 0 at the end, since you may have images that do not have exactly the same colors. Thus you might get a sum that is not fully white, because the two channels were close in color, but not the same. Thus the difference would fall between black and white.
Note that -compose difference is the absolute value of the subtraction of one image with another. It will never be negative. Any negative value from the subtraction is negated so that the result is positive.
Ah so it looks like the main reason i was struggling was because i thought -compose difference would also diff the alpha channel. Looks like magick by default only uses rgb for its operators unless told (default setting is: RGBK,sync)
Quick question: Why is it necessary to reset the channel settings before adding all the images together?