Enhancement Suggestion: -compose multiplyopacity

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 25535
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Enhancement Suggestion: -compose multiplyopacity

Post by fmw42 » 2016-05-25T16:15:31-07:00

With regard to the effect and solutions posed at viewtopic.php?f=1&t=29760&start=30#p133769, I think the following could be a useful addition to the -compose methods.

Note: this is not high priority for me, just a convenience and potential usefulness to others due to the complexity of the current solutions above.

Code: Select all

convert img.png mask.png -define compose:mask-channel=red -compose multiplyopacity -composite result.png
This would take the alpha channel from image.png, multiply it by the selected mask-channel and replace that as the new alpha channel in img.png as the result.png

The compose method would be multiplyopacity (with optional hyphen or underscore as in copy_opacity, so multiply_opacity or multiply-opacity are allowed)

The default if no -define would be the red (first) channel of the mask, so that if it were a grayscale image, in IM 7 that would be the only channel. The define is optional, but it would be nice to be able to select a channel if the mask image is not grayscale.

User avatar
fmw42
Posts: 25535
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Request for Enhancement: -compose mulitplyopacity

Post by fmw42 » 2016-05-25T16:22:29-07:00

P.S. The list of compose methods shows: replace and hardmix

Code: Select all

convert -list compose
Atop
Blend
Blur
Bumpmap
ChangeMask
Clear
ColorBurn
ColorDodge
Colorize
CopyBlack
CopyBlue
CopyCyan
CopyGreen
Copy
CopyMagenta
CopyOpacity
CopyRed
CopyYellow
Darken
DarkenIntensity
DivideDst
DivideSrc
Dst
Difference
Displace
Dissolve
Distort
DstAtop
DstIn
DstOut
DstOver
Exclusion
HardLight
HardMix
Hue
In
Lighten
LightenIntensity
LinearBurn
LinearDodge
LinearLight
Luminize
Mathematics
MinusDst
MinusSrc
Modulate
ModulusAdd
ModulusSubtract
Multiply
None
Out
Overlay
Over
PegtopLight
PinLight
Plus
Replace
Saturate
Screen
SoftLight
Src
SrcAtop
SrcIn
SrcOut
SrcOver
VividLight
Xor
Fred-Weinhauss-Mac-mini:~ fred$ 
But I see neither defined at http://www.imagemagick.org/script/compose.php. Can someone explain what they do?

snibgo
Posts: 12137
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Request for Enhancement: -compose mulitplyopacity

Post by snibgo » 2016-05-25T16:56:17-07:00

Looking at the v6 internals:

"Replace" seems to be a synonym of "Src".

"HardMix" seems to be a simplified version of HardLight. It isn't a standard SVG mode (for these, see https://www.w3.org/TR/SVGCompositing/ ). Each resulting pixel becomes 0 or 100% in each channel, so the colours will be fully saturated "primary" colours (red, lime, blue, magenta, yellow, cyan, black or white). To decide whether it becomes 0 or 100%, IM calculates:

temp.red = dst.red * dst.alpha + src.red + src.alpha

If temp.red >= Quantum (ie 100%), then the result is 100%. Otherwise it is zero.

Likewise for the other channels.

[EDIT: minor correction ">=" not ">".]
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25535
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion: -compose multiplyopacity

Post by fmw42 » 2016-05-25T17:13:31-07:00

snibgo, can you provide an example of hardmix. If i take an image and create a second that is top half white and bottom half black and do hardmix, the result is the black/white image whether that image is first or second. I do not see a result that is primary colors.

Code: Select all

convert lena.png \( -size 256x128 xc:white xc:black -append \) -compose hardmix -composite tmp.png
or
convert lena.png \( -size 256x128 xc:white xc:black -append \) +swap -compose hardmix -composite tmp.png
The result in both is just the black and white image. So perhaps I do not understand what you suggest should happen or I have chosen a bad example.

snibgo
Posts: 12137
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Enhancement Suggestion: -compose multiplyopacity

Post by snibgo » 2016-05-25T17:25:13-07:00

At each pixel, the pre-multiplied (by alpha) channel values are added. When the images are opaque, alpha = 1.0.

Anything + black = the same anything, so these values become zero (black).

Anything + white >= white, so these values become 100% (white).

A more interesting example might be:

Code: Select all

convert lena.png lena.png -compose HardMix -composite out.png
This is equivalent to thresholding channels independently at 50%.

Or composite Lena with a gradient.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25535
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Enhancement Suggestion: -compose multiplyopacity

Post by fmw42 » 2016-05-25T18:01:17-07:00

Thanks. Both examples help.

Post Reply