The difference function is used to calculate the difference between two images. The result is completely transparent where the two images are the same, and the left hand image (lhs) when the images are different. The idea is that if you use over, when the result is layered over the right hand image (rhs) you get the left hand image again, to the greatest extent possible.
Think of this as the difference of a composite image and a background image, yielding a foreground image.
The optional alpha argument says how you wish the alpha channel to contribute. The valid range is 1..255, where 0 is completely transparent and 255 is completely opaque. The default is 255, the result is opaque for pixels which are different. By specifying a non-zero alpha, the result is calculated to work for the given alpha value. If the given alpha channel value would result in out-of-range color channel values, it will attempt to adjust the alpha (on a per pixel basis) to bring them back into range. Note that, even with automatic adjustments, the results may not be perfect as the pixel values will be clipped to a 0..255 range.
icomp 'difference( composite.png , background.png )' -o foreground.png ![]()
The optional alpha argument says how much part you wich the alpha channel to play. The default is zero, no alpha channel, the result is opaque for the different areas. By specifying a non-zero alpha, the result is calculated to work for the given alpha value. Note that the results may not be perfect as the pixel values will be clipped to a 0..255 range.
The difference_bg function is used to calculate the difference between two images. The idea is that when the right hand image (rhs) is layered over the result, you get the left hand image (lhs) again, to the greatest extent possible.
Think of this as the difference of a composite image and a foreground image, yielding a background image.
icomp 'difference_bg( composite.png , foreground.png )' -o background.png ![]()
Transparency in the foreground image (full and partial) is catered for. Partial transparency allows the background to be reconstructed. An opaque foregound pixel yields a transparent background pixel, as there is no data from which to reconstruct the background. The graycstoration -inpaint option can be very useful in reconstructing the missing background image data.