I'm trying to cut out a shape from an image based on a mask I have. I tried a number of ways but I'm really struggling to get the result I need. I'm using ImageMagick 7.1.0-51 Q16-HDRI on Windows.
The "base" image:
Face:
magick hair.png face.png -alpha off -colorspace gray -negate -compose difference -composite -negate result.png
Result:
If you want pure white in the face area, threshold the two images after the conversion to grayscale
magick hair.png face.png -alpha off -colorspace gray -auto-threshold otsu -negate -compose difference -composite -negate result2.png
Result 2:
ADDITION
If your input images have transparent backgrounds, then you have to extract the alpha channels, combine them to do the difference and then put that alpha channel back on the input.
Unix Syntax:
magick hair.webp \
\( clone face_mask.webp -alpha extract -compose difference -composite \) \
-alpha off -compose copy_opacity -composite result.png
For Windows,remove the \ in front of the parentheses and change the end of line \ to ^.