Here is a minimally modified version of Bart's script that differs as follows:
In the "downsample" method, the same DoG is used for both gammas, and the per channel median of the unsharpened, gamma 1 sharpened and gamma 3 sharpened is used to "blend".
I see some evidence that this may be the best method so far, at least in terms of taming haloing without introducing occasional outliers.
(No windows machine: Feel free to fix my direct *n*x translation.)
P.S. Apparently I changed the encoding or something like this. Hopefully I got the Windowese right this time. Just in case, I am cutting and pasting the alt bat file here (I think I'm still missing the CTRL-Ms):
@ECHO OFF
REM Edit the codeline below to point to the location of the most recent version of
REM ImageMagick on your computer if the correct convert command is not recognized.
REM SET PATH=C:\Program Files\ImageMagick-6.8.9-Q16;%PATH%
ECHO *****************************************
ECHO ** IMAGE RESAMPLING **
ECHO *****************************************
ECHO * Halo minimization by Gamma blending, *
ECHO * as suggested by Nicolas Robidoux. *
ECHO * *
ECHO * Author : Bart van der Wolf *
ECHO * *
ECHO * Suggestions for code optimization: *
ECHO * Alan Gibson, Nicolas Robidoux, *
ECHO * Fred Weinhaus *
ECHO * *
ECHO * Version: 1.2.2 *
ECHO * Date : 2014.08.12 *
ECHO * *
ECHO * The Author(s) of this free tool shall *
ECHO * not be liable for any damages that *
ECHO * might result from the use of this *
ECHO * tool. Feel free to not use it. *
ECHO *****************************************
REM Ignore this for the moment, it's unfinished, for future support when dragging/dropping multiple files
REM FOR %%I IN (*.GIF *.JPG *.JPEG *.PNG *.TIF *.TIFF)
REM
:imsize
ECHO.
SET mSize="?"
ECHO Input the magnification percentage (e.g. 50%%), or fit
ECHO inside the requested pixel dimensions (e.g. 800x800,
SET /p mSize= or a max width 800x, or a max height x800):
IF %mSize% EQU "?" SET mSize=800x800
IF %mSize% EQU "" GOTO imsize
:method
ECHO.
SET UpDwn=d
SET /p UpDwn= Use an optimized Up- or Down-sampling method? [U]p, [D]own:
IF /i %UpDwn% GEQ d IF /i %UpDwn% LEQ down GOTO downsample
IF /i %UpDwn% GEQ u IF /i %UpDwn% LEQ up GOTO generic
GOTO method
:generic
SET deblurAmount=50
SET /p deblurAmount= Sharpening amount? (none=0, default/normal=50, high=100+):
for /f "usebackq" %%L in (`identify ^
-precision 16 -format "deblurValue=%%[fx:1-0.0011450938298236*%deblurAmount%]" ^
xc:`) do set %%L
REM IF /i %deblurAmount% EQU -1 GOTO generic
ECHO.
ECHO Creating the resampled image, please wait ...
convert ( -quiet "%~1" -type TrueColor -write "%~dp1IMsource.icc" -depth 16 -set colorspace sRGB -colorspace RGB ) ^
( -clone 0 -gamma 3 -define filter:blur=%deblurValue% -filter Lanczos -distort Resize %mSize% -gamma 0.3333333333333333 ) ^
( -clone 0 -define filter:blur=%deblurValue% -filter Lanczos -distort Resize %mSize% ) ^
-delete 0 ^
( -clone 1 -colorspace gray -auto-level ) ^
-compose over -composite ^
-set colorspace RGB -colorspace sRGB ^
-quality 100 -sampling-factor 4:4:4 ^
-profile "%~dp1IMsource.icc" -compress Lossless "%~dpn1_%mSize%%~x1"
REM Experimental
IF /i %deblurAmount% LEQ 0 GOTO addDeconv
GOTO finish
:downsample
SET sharpAmount="?"
SET /p sharpAmount= Sharpening amount? (none=0, normal=50+, default=100):
IF /i %sharpAmount% == 0 GOTO nodownsharp
IF %sharpAmount% EQU "?" SET sharpAmount=100
ECHO.
ECHO Creating the Down-sampled image with output sharpening, please wait ...
convert ( -quiet "%~1" -type TrueColor -write "%~dp1IMsource.icc" -depth 16 -set colorspace sRGB -colorspace RGB ^
-define filter:c=0.1601886205085204 -filter Cubic -distort Resize %mSize% ) ^
( -clone 0 -define convolve:scale=^%sharpAmount%%%,100 ^
-morphology Convolve DoG:3,0,0.4806768770037563 ) ^
( -clone 0 -gamma 3 -define convolve:scale=^%sharpAmount%%%,100 ^
-morphology Convolve DoG:3,0,0.4806768770037563 -gamma 0.3333333333333333333 ) ^
-evaluate-sequence median ^
-set colorspace RGB -colorspace sRGB ^
-quality 100 -sampling-factor 4:4:4 ^
-define png:preserve-iCCP ^
-profile "%~dp1IMsource.icc" -compress Lossless "%~dpn1_%mSize%%~x1"
REM Experimental
IF /i %sharpAmount% LEQ 0 GOTO addDeconv
GOTO finish
:nodownsharp
ECHO.
ECHO Creating the Down-sampled image without additional sharpening, please wait ...
convert ( -quiet "%~1" -type TrueColor -write "%~dp1IMsource.icc" -depth 16 -set colorspace sRGB -colorspace RGB ^
-filter Quadratic -distort Resize %mSize% ) ^
-set colorspace RGB -colorspace sRGB ^
-quality 100 -sampling-factor 4:4:4 ^
-profile "%~dp1IMsource.icc" -compress Lossless "%~dpn1_%mSize%%~x1"
REM Experimental
GOTO addDeconv
GOTO finish
REM *** DECONVOLUTION ***
:addDeconv
ECHO.
SET Deconv=n
SET /p Deconv= Apply additional deconvolution sharpening? [Y]es, or default [N]o:
IF /i %Deconv% GEQ y IF /i %Deconv% LEQ yes GOTO deconvolve
IF /i %Deconv% GEQ n IF /i %Deconv% LEQ no GOTO finish
GOTO addDeconv
:deconvolve
SET detailSize=0
SET /p detailSize= Blur size in pixels (e.g. blurred edge width, radius of blur):
IF /i %detailSize% LEQ 0 GOTO deconvolve
SET sharpAmount=50
SET /p sharpAmount= Sharpening amount? (none=0, default/normal=50, high=100+):
:noDeconvDialog
for /f "usebackq" %%L in (`identify ^
-precision 16 -format "blurSigma=%%[fx:max(0.4,0.3902*%detailSize%)]" ^
xc:`) do set %%L
ECHO.
ECHO Deconvolving the image, please wait ...
convert ( -quiet "%~dpn1_%mSize%%~x1" -type TrueColor -write "%~dp1IMsource.icc" -depth 16 -set colorspace sRGB -colorspace RGB ) ^
( -clone 0 -gamma 3 -define convolve:scale=^%sharpAmount%%%,100 ^
-morphology Convolve DoG:0,0,%blurSigma% -gamma 0.3333333333333333 ) ^
( -clone 0 -define convolve:scale=^%sharpAmount%%%,100 ^
-morphology Convolve DoG:0,0,%blurSigma% ) ^
-delete 0 ^
( -clone 1 -colorspace gray -auto-level ) ^
-compose over -composite ^
-set colorspace RGB -colorspace sRGB ^
-quality 100 -sampling-factor 4:4:4 ^
-profile "%~dp1IMsource.icc" -compress Lossless "%~dpn1_%mSize%%~x1"
GOTO finish
:finish
REM Clear environment variables
SET blurSigma=
SET deblurAmount=
SET deblurValue=
SET Deconv=
SET detailSize=
SET mSize=
SET sharpAmount=
SET UpDwn=
REM Delete temporary profile copy
IF EXIST "%~dp1IMsource.icc" DEL "%~dp1IMsource.icc"
ECHO.
ECHO *************************************
ECHO *** Your resampled file is Ready! ***
ECHO *************************************
ECHO.
PAUSE