©
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
(PECL imagick 2.0.0)
Imagick::sigmoidalContrastImage — Adjusts the contrast of an image
$sharpen
, float $alpha
, float $beta
[, int $channel
= Imagick::CHANNEL_ALL
] )
Adjusts the contrast of an image with a non-linear sigmoidal contrast
algorithm. Increase the contrast of the image using a sigmoidal transfer
function without saturating highlights or shadows. Contrast indicates
how much to increase the contrast (0 is none; 3 is typical; 20 is
pushing it); mid-point indicates where midtones fall in the resultant
image (0 is white; 50 is middle-gray; 100 is black). Set sharpen to
TRUE
to increase the image contrast otherwise the contrast is reduced.
See also » ImageMagick v6 Examples - Image Transformations — Sigmoidal Non-linearity Contrast
sharpen
If true increase the contrast, if false decrease the contrast.
alpha
The amount of contrast to apply. 1 is very little, 5 is a significant amount, 20 is extreme.
beta
Where the midpoint of the gradient will be. This value should be in the range 0 to 1 - mutliplied by the quantum value for ImageMagick.
channel
Which color channels the contrast will be applied to.
成功时返回 TRUE
。
Example #1 Create a gradient image using Imagick::sigmoidalContrastImage() suitable for blending two images together smoothly, with the blending defined by $contrast and $the midpoint
<?php
function generateBlendImage ( $width , $height , $contrast = 10 , $midpoint = 0.5 ) {
$imagick = new Imagick ();
$imagick -> newPseudoImage ( $width , $height , 'gradient:black-white' );
$quanta = $imagick -> getQuantumRange ();
$imagick -> sigmoidalContrastImage ( true , $contrast , $midpoint * $quanta [ "quantumRangeLong" ]);
return $imagick ;
}
?>
错误时抛出 ImagickException。
[#1] SkepticaLee [2015-11-28 11:05:39]
The formula for sigmoidal contrast given by Thyssen is missing a term. It should be:
( 1/(1+exp(??*(??-u))) - 1/(1+exp(??*??)) ) / ( 1/(1+exp(??*(??-1))) - 1/(1+exp(??*??)) )
where there was an ?? missing from the second term.
Note that a sigmoidal contrast with ?? = 6 and ?? = 0.46 is approximately equivalent to combining a "screen" overlay of the image on itself, followed by a "multiply" overlay.
[#2] acameron at theatomgroup dot com [2013-12-17 19:48:25]
The documentation for this function really isn't useful or helpful at all. "Sharpen", "Contrast" and "Midpoint" aren't the names of the params, which are referred to as "alpha" and "beta".
The Imagemagick manual entry:
For those interested, the corrected formula for the 'sigmoidal non-linearity contrast control' is...
( 1/(1+exp(??*(??-u))) - 1/(1+exp(??)) ) / ( 1/(1+exp(??*(??-1))) - 1/(1+exp(??*??)) )
Where ?? is the threshold level, and ?? the contrast factor to be applied.
The formula is actually very simple exponential curve, with the bulk of the above formula is designed to ensure that 0 remains zero and 1 remains one. That is, the graph always goes though the points 0,0 and 1,1. And the highest gradient of change is at the given threshold.
Src: http://www.imagemagick.org/Usage/color_mods/#sigmoidal
In the Imagick extension source, the function call is:
status = MagickSigmoidalContrastImageChannel(intern->magick_wand, channel, sharpen, alpha, beta);
Src: https://github.com/mkoppanen/imagick/
Referring back to the binary API call gives:
foreign import ccall "MagickSigmoidalContrastImageChannel" magickSigmoidalContrastImageChannel
:: Ptr MagickWand
-> ChannelType -- ^ identify which channel to level: `redChannel`, `greenChannel`
-> MagickBooleanType -- ^ increase or decrease image contrast
-> CDouble -- ^ strength of the contrast, the larger the number the more 'threshold-like' it becomes
-> CDouble -- ^ midpoint of the function as a color value 0 to `quantumRange`
-> IO MagickBooleanType
Src: http://hackage.haskell.org/package/imagemagick-0.0.2/docs/src/Graphics-ImageMagick-MagickWand-FFI-WandImage.html
So the parameters should apparently be interpreted:
Sharpen: 0/1 (increase/decrease contrast)
Alpha: Strength of the contrast (typically 3-20)
Beta: Midpoint of the contrast (typically 50)