IM v6 by default doesn't process alpha. IM v7 by default
does process alpha, so we can use "-alpha off" when we really don't want alpha.
"-fx" is evaluated at every pixel, so I replace that with "-evaluate Add %%[fx:...]" etc where the fx is evaluated only once per image.
I use "-compose Distort -composite" for the distorton, after setting the map green channel to a linear gradient.
I store the map in a 32-bit floating-point miff, and make a PNG but only for ease of viewing.
I've retained Anthony's separate commands. They could be combined into a single command. Windows BAT syntax:
Code: Select all
rem See https://www.imagemagick.org/Usage/mapping/#spherical
set SIZE=1000x1000
%IMG7%magick ^
-define compose:clamp=off ^
-size %SIZE% gradient:Black-White ^
-evaluate Add %%[fx:QuantumRange/h/2-QuantumRange/2] ^
-function Polynomial -4,0,1 ^
-evaluate Pow 0.5 ^
( -size %SIZE% gradient: -rotate 90 ^
-evaluate Subtract 50%% ^
) ^
-compose DivideDst -composite ^
-evaluate Add 50%% ^
-size %SIZE% gradient:Black-White ^
( +clone ) ^
-combine ^
-alpha off ^
-define quantum:format=floating-point ^
-depth 32 ^
+write sphere_lut2.miff ^
sphere_lut2.png
%IMG7%magick ^
-size %SIZE% xc:black ^
-fill white ^
-draw "circle %%[fx:w/2-1/2],%%[fx:h/2-1/2] %%[fx:w/2-1/2],0" ^
-alpha off ^
sphere_mask.png
%IMG7%magick ^
sphere_mask.png ^
( +clone -blur 0x20 -shade 110x21.7 -contrast-stretch 0%% ^
+sigmoidal-contrast 6x50%% ^
-fill grey50 -colorize 10%% ^
) ^
-compose Over -composite ^
-alpha off ^
sphere_overlay.png
%IMG7%magick ^
lena.png -resize %SIZE% ^
sphere_lut2.miff ^
-compose Distort -composite ^
sphere_overlay.png -compose HardLight -composite ^
sphere_mask.png -alpha off -compose CopyOpacity -composite ^
sphere_lena3.png