@@ -28,12 +28,19 @@ function sigmoid(float $alpha, float $beta, bool $ushort = FALSE): Vips\Image
28
28
$ lut = $ lut ->divide ($ max );
29
29
30
30
# the sigmoidal equation, see
31
+ #
31
32
# 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 );
37
44
38
45
# rescale back to 0 - 255 or 0 - 65535
39
46
$ result = $ result ->multiply ($ max );
@@ -93,7 +100,7 @@ function sigLAB(Vips\Image $image, float $alpha, float $beta): Vips\Image
93
100
# $beta == 10 is a large contrast boost, values below about 4 drop the contrast
94
101
#
95
102
# 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 );
97
104
98
105
$ im ->writeToFile ($ argv [2 ]);
99
106
0 commit comments