Imagick::sigmoidalContrastImage

(PECL imagick 2, PECL imagick 3)

Imagick::sigmoidalContrastImageРегулирует контраст изображения

Описание

public function Imagick::sigmoidalContrastImage(
    bool $sharpen,
    float $alpha,
    float $beta,
    int $channel = Imagick::CHANNEL_DEFAULT
): bool

Метод регулирует контрастность изображения нелинейным сигмоидальным алгоритмом. Алгоритм увеличивает контрастность сигмоидальной передаточной функцией без насыщения светлых участков или теней. Параметр alpha задаёт степень увеличения контрастности: 0 — без изменений, 3 — типичное значение, 20 — предельное. Параметр beta определяет положение средних тонов в результирующем изображении: 0.00 — белый; 0.50 — средний серый; 1.00 — чёрный. При установке параметру sharpen значения true контрастность изображения увеличивается, иначе контрастность уменьшается.

Подробнее об алгоритме рассказывает раздел » Примеры ImageMagick -- Изменения цвета — Сигмоидальная нелинейная контрастность.

Список параметров

sharpen

При передаче значения true контраст увеличивается, при false — уменьшается.

alpha

Степень изменения контрастности: 1.00 — незначительно, 5.00 — значительно, 20 — предельно.

beta
Точка перегиба градиента: произведение значения в диапазоне от 0 до 1 и предельного для текущей сборки библиотеки ImageMagick значения квантового диапазона.
channel

Цветовые каналы, к которым требуется применить контраст.

Возвращаемые значения

При успешном выполнении функция возвращает true.

Ошибки

При ошибке функция выбрасывает исключение ImagickException.

Примеры

Пример #1 Пример создания градиентного изображения методом Imagick::sigmoidalContrastImage() для плавного смешивания двух изображений с заданным контрастом и центром градиента

<?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;
}

Добавить

Примечания пользователей 2 notes

up
4
acameron at theatomgroup dot com
12 years ago
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)
up
0
SkepticaLee
10 years ago
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.
To Top