Reputation: 31871
I'm trying to do what I think is a simple operation buy just can't figure out the command-line options for convert
. I have two images and would like to subtract the one from the other.
subtract
results in
I know it must involve a -composite
comand with a -compose
option but I can't figure out which. Either it does the inverse of what I want, creates a smaller region (when the cut-out part is a smaller image), or just does something else.
NOTE: In the second image it is the alpha-channel that should be subtracted, ignoring the color. A fully opaque pixel will be fully removed from the result, transparent ones left untouched, and partial ones partially removed. The second image may not be the same size as the first one. Ultimately a geometry offset must be applied and the example here is just for simplicity purposes.
What is the command-line to achieve what I want?
Note: I'd like the command-line for convert
and not compose
because it will actually be the final step in a longer command-line.
Upvotes: 3
Views: 2077
Reputation: 31871
I got some help from the IM forums. The below does what I requested. It copies the alpha channel from the circle onto the square image. That gives me the opposite alpha to what I want, so I negate that channel to get the desired result.
convert square.png circle_small.png -gravity center -compose CopyOpacity \
-composite -channel A -negate a.png
Upvotes: 2
Reputation: 337
This works as you described, and you can do this at the end of a command chain:
convert -channel Alpha -compose subtract -composite circle.png square.png -write mpr:orig +delete \
-channel RGB -compose add -composite mpr:orig square.png output.png
I used mpr to save the result of the first operation. Obviously, the trick is to first subtract the respective alpha channels, and then add RGB channels of the subtraction and the square.
Upvotes: 0
Reputation: 207465
I know you said you want the convert command line, but this may help you work out how to get there...
convert -negate b.png invb.png
composite -compose Lighten a.png invb.png c.png
I named your leftmost image "a" and the next one "b". I am sure there is an easier way - we just need someone clever to come along and tell us!
Upvotes: 0