Page 1 of 1

Possible bugs with masking in IM 7

Posted: 2018-05-03T10:18:02-07:00
by fmw42
IM 7.0.7.29 Q16

I am having trouble with using -region and -read-mask, -write-mask, -mask in IM 7. The results are either the whole image is processed or a black image. Perhaps I misunderstand how these work in IM 7.

Input:
Image

In IM 6, I can do -region as follows, which works fine:

Code: Select all

convert lena.jpg \
-region 128x128+64+64 -scale 10% -scale 1000% +region \
lena_pixelate_region6.jpg
Image

In IM7, I get a black image

Code: Select all

magick lena.jpg \
-region 128x128+64+64 -scale 10% -scale 1000% +region \
lena_pixelate_region7.jpg
Image

The porting document says:
-region
The draw transformations are relative to the upper left corner of the image, previously in IMv6 they were relative to the region.
But I am not sure I understand what that means.

The porting document also says:
For convenience, we continue to support the -mask option in version 7 to match the behavior of version 6.
But this does not seem to be true.

Code: Select all

magick lena.jpg \
\( +clone -fill white -colorize 100 \
-fill black -draw "circle 128,128 64,128" -alpha off +write tmp.png -write mpr:circle +delete \) \
-mask mpr:circle -scale 10% -scale 1000% -mask \
lena_pixelate_mask7.jpg
magick: option deprecated, unable to execute `-mask' at CLI arg 20 @ error/operation.c/CLIOption/5212.

The porting document also has an example:

Code: Select all

convert rose: -write-mask rose_bg_mask.png -modulate 110,100,33.3  +mask rose_blue.png
magick: option deprecated, unable to execute `+mask' at CLI arg 6 @ error/operation.c/CLIOption/5212.

So the +mask above should be replaced with +write-mask. Also convert in IM 7 porting document should be replaced with magick and compare with magick compare.

However, the write-mask polarity in IM 7 seems to be opposite that of IM 6, so the above command is affecting the outside, not the inside as the original example did in Anthony's documents

The porting document says that as follows:
Version 7 supports masks for most image operators. ... From the command-line, you can associate a mask with an image with the -read-mask and -write-mask options. This polarity is the reverse of masks in version 6 of ImageMagick.
However, this example does not work the same as in IM 6. See https://www.imagemagick.org/Usage/masking/#write_mask

IM 6:

Code: Select all

convert rose: -mask rose_bg_mask.png -modulate 110,100,33.3  +mask rose_blue6.png
Image

IM 7 (with mask polarity reversed):

Code: Select all

magick rose: -write-mask rose_bg_mask_negate.png -modulate 110,100,33.3  +write-mask rose_blue7.png
Image


With regard to -write-mask and -read-mask, these are failing for me as below with respect to -scale. Perhaps that is not a valid command for masking due to scale change.

IM7 -write-mask makes a black image

Code: Select all

magick lena.jpg \
\( +clone -fill black -colorize 100 \
-fill white -draw "circle 128,128 64,128" -alpha off +write mask.png -write mpr:circle +delete \) \
-write-mask mpr:circle -scale 10% -scale 1000% +write-mask \
lena_pixelate_write7.jpg
Image


IM7 -read-mask does the scaling everywhere, not just the center circle

Code: Select all

im7 magick lena.jpg \
\( +clone -fill black -colorize 100 \
-fill white -draw "circle 128,128 64,128" -alpha off +write mask.png -write mpr:circle +delete \) \
-read-mask mpr:circle -scale 10% -scale 1000% +read-mask \
lena_pixelate_read7.jpg
Image

Re: Possible bugs with masking in IM 7

Posted: 2018-05-04T10:58:30-07:00
by magick
Recall, bug reports must be atomic. You discuss -region and -mask. We''ll address your first concern -region. This option has a behavioral change from IMv6. IMv6 has a number of "conveniences" such as -region that was removed from IMv7. The IMv7 design is more atomic so there is almost always a one-to-one relationship between an option and its behavior. For IMv7, -region sets a write mask for the region you define. In IMv6, a separate-mask image was cloned instead, operated on, and the results were composited onto the source image. A write mask is more efficient and works well if you want to operate directly on the region such as this command:

Code: Select all

magick lena.jpg -region 128x128+64+64  -negate negate.png
For your use case, you need to manually apply the composite yourself:

Code: Select all

magick lena.jpg \( -clone 0 -crop 128x128+64+64 -scale 10% -scale 1000% \) -geometry 128x128+64+64 -composite pixelate.jpg

Re: Possible bugs with masking in IM 7

Posted: 2018-05-04T11:54:31-07:00
by fmw42
Sorry about information overload. I will try to limit my bug reports in the future to one topic.

It seems that you are suggesting that -region in IM 7 (and probably similarly for the masking issues) do not work with commands that change scale (as they did in IM 6), which is what I has thought might be the issue.