Page 1 of 3
Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T15:13:56-07:00
by chaoscarnage
I had a system setup where it masked 1 image with 2 masks.
The code that previously worked was...
Code: Select all
IMAGE_BEING_MASKED.png
\(
\( MASK_IMAGE_1.png -alpha copy \) -compose Dst_In -composite -alpha disassociate
\)
\(
\( MASK_IMAGE_2.png -alpha copy \) -compose Dst_In -composite -alpha disassociate
\) -compose Over -composite
FINISHED_IMAGE.png
(spaces added to make it more readable)
fmw42 stated that disassociate does not exist. I got that command from
here.
I was using version 7.0.5-7 and upgraded to 7.0.8-8 and now this no longer works.
Could someone please help me get this fixed.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T15:42:53-07:00
by fmw42
Please post your working images and an example of your output that is what you expect. You can post them to some free hosting service that will not change the image format (such as dropbox.com) and put the URLs here. This forum does not support direct upload of images.
From your link, now I do see -alpha disassocate, which I believe is only for IM 7.
But I am still confused why you use it and why you are doing -alpha copy on your mask.
Your command above needs a "convert" or "magick" at the beginning.
I am not aware that 3-image masked composites work with a mask image with an alpha channel (via -alpha copy).
Masked composites are discussed at
https://www.imagemagick.org/Usage/compose/#compose
I am unclear what you are trying to do. Once you do your first composite, you only have the composite image remaining. Thus the second composite is not a masked composite. It is using your MASK_IMAGE2 as the second image.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:00:07-07:00
by chaoscarnage
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:25:43-07:00
by fmw42
Thanks for posting your example. It is now much more clear what you want.
This should do it. I take the alpha channel from the image and multiply it with the two masks to make a new mask that I put back into the alpha channel of the input.
Code: Select all
magick image.png \
\( -clone 0 -alpha extract mask1.png mask2.png -evaluate-sequence multiply -composite \) \
-alpha off -compose copy_opacity -composite \
result.png
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:27:23-07:00
by chaoscarnage
The masks are black and white masks. Using DST_IN. I still need to be using DST_IN
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:28:05-07:00
by fmw42
chaoscarnage wrote: ↑2018-08-05T16:27:23-07:00
The masks are black and white masks. Using DST_IN. I still need to be using DST_IN
No you do not. My method assumes that all the images that are multiplied to create a final mask started as simply black/white with no transparency.
There are probably many ways to do this. Mine is just one that is pretty simple and works fine, at least for this example.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:29:50-07:00
by chaoscarnage
fmw42 wrote: ↑2018-08-05T16:25:43-07:00
Thanks for posting your example. It is now much more clear what you want.
This should do it. I take the alpha channel from the image and multiply it with the two masks to make a new mask that I put back into the alpha channel of the input.
Code: Select all
magick image.png \
\( -clone 0 -alpha extract mask1.png mask2.png -evaluate-sequence multiply -composite \) \
-alpha off -compose copy_opacity -composite \
result.png
Here's where you and I talked about it before.
viewtopic.php?f=1&t=32582&p=149200#p149200
It's the exact same thing but the example you used back then no longer works in this version of Imagemagick.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:30:57-07:00
by chaoscarnage
fmw42 wrote: ↑2018-08-05T16:28:05-07:00
chaoscarnage wrote: ↑2018-08-05T16:27:23-07:00
The masks are black and white masks. Using DST_IN. I still need to be using DST_IN
No you do not. My method assumes that all the images that are multiplied to create a final mask started as simply black/white with no transparency.
There are probably many ways to do this. Mine is just one that is pretty simple and works fine, at least for this example.
I absolutely do. Or it would be thousands of hours of work to change the library of masks we have made.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:34:08-07:00
by fmw42
I do not recall that discussion, but it seems to be unresolved and unclear why you needed dat_in. I do not recall you providing those images that I used. Was that provided offline.
If my method above works fine, why go back to dst_in. If the mask works here and you have similar masks, then this method should work for other cases.
If you have other examples for which this does not work, then provide those examples so we can see your more general situation and modify the code appropriately.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:40:18-07:00
by chaoscarnage
We compile command strings based on what overall image is being built and then send it off to the command line to run, so we need it to be modular and we want to do as much of it as we can at once. We have to use DST_IN because we have other commands that use DST_OUT and it uses the last command you told it to use as the default. This generates strings from time to time that are 200 images being made into a single image at once. This all worked great up until the update.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:40:22-07:00
by fmw42
Your older example has 3 images and 2 masks. So it is a different case. I reproduced the same outputs as before using:
IM 6.9.10.8
Code: Select all
convert blank.png \
\( red.png \( mask1.png -alpha copy \) -compose Dst_In -composite \) \
-compose Over -composite \
\( blue.png \( mask2.png -alpha copy \) -compose Dst_In -composite \) \
-compose Over -composite red_blue_mask_im6.png
IM 7.0.8.8
Code: Select all
magick blank.png \
\( red.png \( mask1.png -alpha copy \) -compose Dst_In -composite \) \
-compose Over -composite \
\( blue.png \( mask2.png -alpha copy \) -compose Dst_In -composite \) \
-compose Over -composite red_blue_mask_im7.png
They still work.
This code will not likely work for other situations for which I have no control or knowledge of what you need.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:42:48-07:00
by chaoscarnage
I am not able to use magick. When I use magick the images break horrible, so I have to use convert in IM 7.
This is what worked until 7.0.8-8
blank.png \
\( red.png \( \( mask1.png -alpha copy \) -compose Dst_In -composite \) \( mask2.png -alpha copy \) -compose Dst_In -composite \) \
-compose Over -composite finalimage.png
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:46:49-07:00
by fmw42
If you are using IM 7, then magick is what is called for. If you use convert, then IM 7 is reverting back to IM 6 to do the work, unless your system has a symbolic link between convert to magick. I suspect you have a bad install of IM 7 if magick does not work. Magick works fine for me as above.
What is your platform? What do you get for
and
Show me at least the version number and date of the version, if not everything that it produces.
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:48:59-07:00
by chaoscarnage
LINUX: magick -version
Version: ImageMagick 7.0.8-8 Q16 x86_64 2018-08-05
https://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License:
https://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): png zlib
LINUX:~$ convert -version
Version: ImageMagick 7.0.8-8 Q16 x86_64 2018-08-05
https://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License:
https://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): png zlib
Re: Masking 1 Image with 2 Masks no longer working.
Posted: 2018-08-05T16:51:14-07:00
by chaoscarnage
The amount of masks that are applied to an image are sometimes greater then 2. Before, I was able to just string the masks together and as a command it would do one after another.