Masking 1 Image with 2 Masks no longer working.

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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

Looks OK and I suspect you have a symbolic link between convert and magick. But that does not explain why "magick" does not work. In what way does in not work? Do either of my commands above work on your old example? Do my new code work if you use convert rather than magick?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

My new methods should work just fine with one image with transparency and any number of black/white masks with no transparency. You can use -evaluate-sequence multiply with any number of images. But your two examples are quite different in the number of input images. In that case you have one mask for each image and also a blank background image.

Post a set of example images that do not work with either of my commands. I can see more from a real-world example.
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Masking 1 Image with 2 Masks no longer working.

Post by chaoscarnage »

I use a buffer image that is blank, and compile everything into it.
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Masking 1 Image with 2 Masks no longer working.

Post by chaoscarnage »

For some reason there are times with magick that it breaks entirely and the transparent image that is being masked, now has a black background. Convert never does this.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

If you save the output to JPG, you will get a black background since JPG does not support transparency. The same if you save to TIFF will JPG compression. Could that be your issue?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

It might be possible that your use of convert is not a symbolic link and your convert in IM 7 is actually calling IM 6 to do the work. But I would have to see an example where IM 7 magick does not work and convert does.
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Masking 1 Image with 2 Masks no longer working.

Post by chaoscarnage »

No, it's a png.

Do you have any other ideas to help apply multiple (dynamically infinite) masks to a single image?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

You can use my new method or you can apply your dst_in as before.

This works fine for me using IM 6 or IM 7

Code: Select all

convert image.png \
\( mask1.png -alpha copy \) -compose dst_in -composite \
\( mask2.png -alpha copy \) -compose dst_in -composite \
result2.png

Code: Select all

magick image.png \
\( mask1.png -alpha copy \) -compose dst_in -composite \
\( mask2.png -alpha copy \) -compose dst_in -composite \
result2.png
You should be able to add more masks in the same way

Code: Select all

magick image.png \
\( mask1.png -alpha copy \) -compose dst_in -composite \
\( mask2.png -alpha copy \) -compose dst_in -composite \
\( mask3.png -alpha copy \) -compose dst_in -composite \
\( mask4.png -alpha copy \) -compose dst_in -composite \
result3.png
Or if you want a blank background the size of the input, then

Code: Select all

magick image.png \
\( -clone 0 -alpha transparent \) +swap -compose over -composite \
\( mask1.png -alpha copy \) -compose dst_in -composite \
\( mask2.png -alpha copy \) -compose dst_in -composite \
result4.png
These all work for me
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

P.S. Your install has only two delegates. Is that what you want?
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Masking 1 Image with 2 Masks no longer working.

Post by chaoscarnage »

Code: Select all

magick buffer.png \
     \( IMAGE_TO_MASK.png  \
          \( MASK1.png -alpha copy \) -compose Dst_In -composite -alpha disassociate \
           \( MASK2.png -alpha copy \) -compose Dst_In -composite -alpha disassociate \
     \) -compose Over -composite OUT_IMAGE.png
If I do this, it will ignore MASK1 and only apply MASK2.


It's done like this because more images are combine into buffer.

Code: Select all

magick /folder/buffer.png \( /folder/0a/70/6d/0410487174583b9d794bf95a571.png \( /folder/d1/9a/63/32bf2bcb08536c78b7be4cf7e2.png -alpha copy \) -compose Dst_In -composite -alpha disassociate \( /folder/18.png -alpha copy \) -compose Dst_In -composite -alpha disassociate \) -compose Over -composite \( /folder/43/56/4c/3c8f642a849782b51d3475d0d7211.png \( /folder/18.png -alpha copy \) -compose Dst_In -composite -alpha disassociate \) -compose Over -composite \( /folder/77/6f/7a/73ab514c223a5aa1e2703c8c34230.png \( /folder/18.png -alpha copy \) -compose Dst_In -composite -alpha disassociate \) -compose Over -composite /outputfolder/ae1b55334da62a012071469e0c24.png
We've never needed more then the two we use. Is there another delegate you feel would be good?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

I do not understand the need for -alpha disassociate. So I cannot help. Did you try my commands above that do not use it.

Sorry I have no idea what you are doing with the last command nor the buffer.png. Is that a pure transparent image?

If you want a buffer, then try this and replace my buffer.png with yours.

Code: Select all

convert -size 100x100 xc:none buffer.png

Code: Select all

convert buffer.png \
image.png -compose over -composite \
\( mask1.png -alpha copy \) -compose dst_in -composite \
\( mask2.png -alpha copy \) -compose dst_in -composite \
result5.png
Repeat as many masks as you want.
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Masking 1 Image with 2 Masks no longer working.

Post by chaoscarnage »

I have a buffer image that is loaded, just in the massive example in the previous past.

I have tried exactly what you have, and it just ignores the first mask. I also removed -alpha disassociate temporarily and still it ignores the first mask.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

Did you try my exact command with the same images that I used. Or did you replace with your buffer and other images. If you cannot duplicate my results with the same images that I used, then I don't think I can help further. It works for me. I cannot reproduce your problem with my code and the examples I used that you provided. I can only surmise that your Imagemagick install is flawed.

Try disabling OpenMP or use one thread and see if that works.

Code: Select all

convert -limit thread 1 ....
chaoscarnage
Posts: 93
Joined: 2012-12-31T15:56:29-07:00
Authentication code: 6789

Re: Masking 1 Image with 2 Masks no longer working.

Post by chaoscarnage »

I have run exactly what you've given me using isolated examples and everytime one mask is ignored.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Masking 1 Image with 2 Masks no longer working.

Post by fmw42 »

Given that you say magick does not always work and that the first mask is ignored and you only have two delegates, I can only assume that your Imagemagick install if flawed.
Post Reply