Skip to content

Commit e9bee8f

Browse files
committed
fix sig.php
there was a missing term in the equation we were using
1 parent d91b499 commit e9bee8f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

examples/sig.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ function sigmoid(float $alpha, float $beta, bool $ushort = FALSE): Vips\Image
2828
$lut = $lut->divide($max);
2929

3030
# the sigmoidal equation, see
31+
#
3132
# http://www.imagemagick.org/Usage/color_mods/#sigmoidal
32-
$x = $lut->multiply(-1)->add($alpha)->multiply($beta)->exp();
33-
$y = exp($beta + 1);
34-
$t1 = $x->divide($y)->add(1);
35-
$t2 = $x->add(1)->pow(-1)->subtract(1 / $y);
36-
$result = $t1->multiply($t2);
33+
#
34+
# though that's missing a term -- it should be
35+
#
36+
# (1/(1+exp(β*(α-u))) - 1/(1+exp(β*α))) /
37+
# (1/(1+exp(β*(α-1))) - 1/(1+exp(β*α)))
38+
#
39+
# ie. there should be an extra α in the second term
40+
$x = 1.0 / (1.0 + exp($beta * $alpha));
41+
$y = 1.0 / (1.0 + exp($beta * ($alpha - 1.0))) - $x;
42+
$z = $lut->multiply(-1)->add($alpha)->multiply($beta)->exp()->add(1);
43+
$result = $z->pow(-1)->subtract($x)->divide($y);
3744

3845
# rescale back to 0 - 255 or 0 - 65535
3946
$result = $result->multiply($max);
@@ -93,7 +100,7 @@ function sigLAB(Vips\Image $image, float $alpha, float $beta): Vips\Image
93100
# $beta == 10 is a large contrast boost, values below about 4 drop the contrast
94101
#
95102
# sigLAB is the fancy one, and is much slower than sigRGB
96-
$im = sigLAB($im, 0.5, 10);
103+
$im = sigLAB($im, 0.5, 7);
97104

98105
$im->writeToFile($argv[2]);
99106

0 commit comments

Comments
 (0)