Pages: 1 ... 15 16 [17] 18 19 ... 24   Go Down

Author Topic: A free high quality resampling tool for ImageMagick users  (Read 240552 times)

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #320 on: September 28, 2014, 12:28:12 pm »

...
Bart:
Thank you for this detailed write up. I take note.
-----
Not sure, but I think the weird pixels or pairs of pixels usually have a clipped channel (blue = 0, for example).
Come to think of it, clipping should be expected to "confuse the heuristic". (I'm running a Q16 version of IM, hence clipping, within the toolchain, is possible.)
I gather that this does not surprise you either.
When sharpening, clipping is really evil.
« Last Edit: September 28, 2014, 12:37:36 pm by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #321 on: September 28, 2014, 02:00:19 pm »

One thing I have not fully figured out is that the gamma 3 result is most likely lighter than the other two even when nothing's happening. Taking the median thus generally returns one either the unsharpened (linear light) result or the gamma 1 result. This may, or may not, be the best thing.
-----
P.S. Here is a very very simple scheme that gets rid of (P.S. most of) the "odd pixels". (Bart: Note that for the specific purpose of downsampling JPEGs or 8-bit sRGB PNGs, I've checked that my shortcuts are harmless).
convert \
  \( input.jpg -set colorspace sRGB -colorspace RGB \
     -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 25\% \) \
  \( -clone 0 -define convolve:scale=50^,100% \
     -morphology Convolve DoG:3,0,0.4806768770037563 \) \
  \( -clone 0 -gamma 3 -define convolve:scale=50^,100% \
     -morphology Convolve DoG:3,0,0.4981063336734057 -gamma 0.3333333333333333333 \) \
  -evaluate-sequence median \
  -set colorspace RGB -colorspace sRGB altdownsample50.png
« Last Edit: September 29, 2014, 06:46:27 am by NicolasRobidoux »
Logged

alain

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 465
Re: A free high quality resampling tool for ImageMagick users
« Reply #322 on: September 28, 2014, 04:18:58 pm »

One thing I have not fully figured out is that the gamma 3 result is most likely lighter than the other two even when nothing's happening. Taking the median thus generally returns one either the unsharpened (linear light) result or the gamma 1 result. This may, or may not, be the best thing.
-----
P.S. Here is a very very simple scheme that gets rid of the "odd pixels". (Bart: Note that for the specific purpose of downsampling JPEGs or 8-bit sRGB PNGs, I've checked that my shortcuts are harmless).
convert \
  \( input.jpg -set colorspace sRGB -colorspace RGB \
     -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 25\% \) \
  \( -clone 0 -define convolve:scale=50^,100% \
     -morphology Convolve DoG:3,0,0.4806768770037563 \) \
  \( -clone 0 -gamma 3 -define convolve:scale=50^,100% \
     -morphology Convolve DoG:3,0,0.4981063336734057 -gamma 0.3333333333333333333 \) \
  -evaluate-sequence median \
  -set colorspace RGB -colorspace sRGB altdownsample50.png

Thanks, would you convert to sRGB before down sampling (aka running above commands) or after?  If doing the conversion after the commands will result in sRGB RGB not completely correct as the gamma would be slightly different.
I supposse running everything in 16-bit will be more than sufficiƫnt?


Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #323 on: September 28, 2014, 05:19:45 pm »

Alain:
My latest script, or the one with identical DoG parameters which I suspect, despite Bart van der Wolf's misgivings, may be slightly better and that I put below, assumes sRGB input. How to best deal with other types of input image depends on the specifics. See Alan Gibson and Bart van der Wolf's scripts for hints of how to handle other situations. Or use your favorite software to produce a 8 or 16 bit sRGB PNG or TIFF (I recommend Perceptual rendering intent over the others) and just replace input.jpg by input.png in what follows. Or ask for help at the ImageMagick User forums.
Here is the "same DoG parameters" version:
convert \
  \( input.jpg -set colorspace sRGB -colorspace RGB \
     -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 25\% \) \
  \( -clone 0 -define convolve:scale=100^,100% \
     -morphology Convolve DoG:3,0,0.4806768770037563 \) \
  \( -clone 0 -gamma 3 -define convolve:scale=100^,100% \
     -morphology Convolve DoG:3,0,0.4806768770037563 -gamma 0.3333333333333333333 \) \
  -evaluate-sequence median \
  -set colorspace RGB -colorspace sRGB -quality 98 output.jpg
Warning: You realize that I'm using this Forum as a sandbox for new methods, right? Definitely no warranty. However feedback, esp. negative, is welcome.
Note: Recent ImageMagick turns off chroma downsampling if the quality is high enough (threshold is -quality 90). If you are using an old version, add the usual -sampling-factor 4:4:4.
P.S. At some point, I'll start adding credits to the source code. Everyone who contributed to Bart's version is of course "in it".
P.S. Bart: I strongly suspect taking the per channel median is better than the "old downsampling". Yes, I'm violating one of my earlier pronouncements. But the trade-off is worth it, it appears, in my limited testing.
« Last Edit: September 28, 2014, 05:43:43 pm by NicolasRobidoux »
Logged

snibgo

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: A free high quality resampling tool for ImageMagick users
« Reply #324 on: September 28, 2014, 05:36:17 pm »

I'm happy to help, where I can. You folks know vastly more about IM filters, convolution etc than I do. You are showing me a whole new world.

Quote from: BartvanderWolf
Also, in the 'old' version I force the processing to 16-bit precision from the start of the conversion with the '-depth 16' parameter, because ImageMagick tends to use the lowest amount of memory if possible (e.g. by using single channel images if 3-channel monochrome images are input), and may (or may not) do some of the processing in 8-bit/channel precision. I'd rather be over-cautious than sorry, and prefer to force bit-depth to 16, even for 8-b/ch input. When experimentation stabilizes, we can always test if it makes any difference for a JPEG workflow, but I want to keep the options for dealing with other input sources open for now.
IM V6 stores images in memory according to the Q-number and HDRI choice. "-depth N" has no effect on this. "-depth N" affects only output to files. Using "-depth N" earlier than required in the command should make no difference, positive or negative.

To reduce clipping when doing gamma operations etc, it is best to use a Q-number greater than the bit depth of input files. For 8-bit inputs, use Q16. For 16-bit inputs, use Q32. When using Q32, "-depth 16" will force the output bit-depth to be 16.

Quote from: NicolasRobidoux
P.S.2 Quick and dirty check of luminance drift. With "neutral" strenght of the DoG, namely 50, I saved the results into pngs, loaded into nip2, converted to XYZ, and compared the Y channel image mean with that of the input. The new scheme is a lot closer. Not conclusive. But encouraging.
The old scheme blended pixels, thus it could generate colours that weren't in any version of the down-sampled input. The new scheme (currently) picks each output pixel from one of the versions of the input, so can't invent new colours.

Another possibility for blending/tie-breaking would be to take, not a (weighted) average of the RGB values, but a (weighted) average of L*a*b* values. Where's that Aspirin?
Logged

alain

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 465
Re: A free high quality resampling tool for ImageMagick users
« Reply #325 on: September 28, 2014, 06:09:28 pm »

Alain:
My latest script, or the one with identical DoG parameters which I suspect, despite Bart van der Wolf's misgivings, may be slightly better and that I put below, assumes sRGB input. How to best deal with other types of input image depends on the specifics. See Alan Gibson and Bart van der Wolf's scripts for hints of how to handle other situations. Or use your favorite software to produce a 8 or 16 bit sRGB PNG or TIFF (I recommend Perceptual rendering intent over the others) and just replace input.jpg by input.png in what follows. Or ask for help at the ImageMagick User forums.
Here is the "same DoG parameters" version:
convert \
  \( input.jpg -set colorspace sRGB -colorspace RGB \
     -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 25\% \) \
  \( -clone 0 -define convolve:scale=100^,100% \
     -morphology Convolve DoG:3,0,0.4806768770037563 \) \
  \( -clone 0 -gamma 3 -define convolve:scale=100^,100% \
     -morphology Convolve DoG:3,0,0.4806768770037563 -gamma 0.3333333333333333333 \) \
  -evaluate-sequence median \
  -set colorspace RGB -colorspace sRGB -quality 98 output.jpg
Warning: You realize that I'm using this Forum as a sandbox for new methods, right? Definitely no warranty. However feedback, esp. negative, is welcome.
Note: Recent ImageMagick turns off chroma downsampling if the quality is high enough (threshold is -quality 90). If you are using an old version, add the usual -sampling-factor 4:4:4.
P.S. At some point, I'll start adding credits to the source code. Everyone who contributed to Bart's version is of course "in it".
P.S. Bart: I strongly suspect taking the per channel median is better than the "old downsampling". Yes, I'm violating one of my earlier pronouncements. But the trade-off is worth it, it appears, in my limited testing.

Thanks and I'm fully aware that it's a sandbox.  For what I'm doing is also no problem, mostly sandbox work to.
Logged

alain

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 465
Re: A free high quality resampling tool for ImageMagick users
« Reply #326 on: September 28, 2014, 06:11:49 pm »

I'm happy to help, where I can. You folks know vastly more about IM filters, convolution etc than I do. You are showing me a whole new world.
IM V6 stores images in memory according to the Q-number and HDRI choice. "-depth N" has no effect on this. "-depth N" affects only output to files. Using "-depth N" earlier than required in the command should make no difference, positive or negative.

To reduce clipping when doing gamma operations etc, it is best to use a Q-number greater than the bit depth of input files. For 8-bit inputs, use Q16. For 16-bit inputs, use Q32. When using Q32, "-depth 16" will force the output bit-depth to be 16.
The old scheme blended pixels, thus it could generate colours that weren't in any version of the down-sampled input. The new scheme (currently) picks each output pixel from one of the versions of the input, so can't invent new colours.

Another possibility for blending/tie-breaking would be to take, not a (weighted) average of the RGB values, but a (weighted) average of L*a*b* values. Where's that Aspirin?

Thanks for the clarification.  I'm I right that there's no Q32 binary for windows?  Not a real need if the output is 8-bit jpg ;-)
Logged

snibgo

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: A free high quality resampling tool for ImageMagick users
« Reply #327 on: September 28, 2014, 06:38:35 pm »

The developers don't release a prebuilt Q32. But it is easy to build yourself, using Cygwin. See my page http://im.snibgo.com/compim.htm
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #328 on: September 29, 2014, 03:42:39 am »

...
The old scheme blended pixels, thus it could generate colours that weren't in any version of the down-sampled input. The new scheme (currently) picks each output pixel from one of the versions of the input, so can't invent new colours.
...
Alan:
Clarification: The new scheme (currently) picks each output pixel from one of the resized versions of the input, so can invent new colours.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #329 on: September 29, 2014, 03:50:43 am »

Bart:
I understand, I believe, the heuristic that justifies using different DoGs for different gammas. I am more concerned, however, about how the two results interact than I am about each of them being "as good as possible" in isolation. Roughly speaking, I see the gamma 3 deconvolution result as a correction of the gamma 1 deconvolution result (and now, as a corrections of the non-deconvolved one).
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #330 on: September 29, 2014, 04:03:46 am »

Side comment: The libvips GUI Nip2 now contains ImageMagick. Installs on "everything". http://libvips.blogspot.dk/2011/06/using-imagemagick-from-nip2.html
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #331 on: September 29, 2014, 04:25:25 am »

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
« Last Edit: September 29, 2014, 03:27:23 pm by NicolasRobidoux »
Logged

snibgo

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: A free high quality resampling tool for ImageMagick users
« Reply #332 on: September 29, 2014, 05:02:35 am »

Quote from: NicolasRobidoux
Clarification: The new scheme (currently) picks each output pixel from one of the resized versions of the input, so can invent new colours.
Yes. Sorry I wasn't clear.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #333 on: September 29, 2014, 05:03:56 am »

Bart: The last graph of http://blog.kasson.com/?p=7296, obtained with EWA RobidouxSoft, LWGB and your chosen pair of DoG parameters, blows my mind.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #334 on: September 29, 2014, 07:20:00 am »

Bart: I think it would be a good idea to add "tensor Triangle" downsampling (-filter Triangle -resize) through linear light to your script, so that people easily see what a fairly neutral (as far as color preservation) scheme does (at least when the input is sRGB).
-----
I am immensely thankful that you picked up on this project. I'm not sure I would have thought of tweaking the post-sharpening so it "fixes" the blurring introduced by an antialiasing EWA method. (Even though it's kind of obvious, at least in hindsight, if you look at things through the right lens.) It was off my radar.
And you brought an immense amount of know how and momentum, without which the project would have moved at a snail's pace.
« Last Edit: September 29, 2014, 07:36:54 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #335 on: September 29, 2014, 09:04:21 am »

It will take some new ideas to eliminate the lightening of high frequency structures.
Here is why, as far as I can tell:
DoG through gamma light lightens high frequency structures.
Now, if you combine DoG through gamma > 1 with two gamma 1 results, the lightening introduced by the high gamma DoG will "bleed through".
At this point this bleed through can be reduced. But I don't know how to completely get rid of it without increasing halos.
« Last Edit: September 29, 2014, 09:25:44 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #336 on: September 29, 2014, 11:50:44 am »

I've compared the average of the Y channel of the fly downsampled with bilinear through linear light to the "per channel median" variant at sharpening = 50, and 50 is not too bad in the drift department and keeps moire under wraps. Increasing the sharpening adds moire, lightens the eyes and raises the average of the Y channel.
"Sharp" has a price. (What a surprise.)
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #337 on: September 30, 2014, 05:36:42 am »

Here is what is hopefully a sufficient fix of the "high frequency detail lightening": use gamma 1.25 instead of gamma 3.
This version does not suppress dark halos as much as earlier ones, but I think that, when one does not pixel peep, it may suppress them enough. No free hot lunch: If you want less halos, push the gamma up from 1.25 (and fix its reciprocal). If you want more "lightness preservation" in high frequency areas, push the gamma down toward 1 (and fix its reciprocal).
This runs considerably more slowly than Bart's original, because it uses a rank filter, and rank filters are slow.
Hopefully the zip file has the right line endings for Windows. Just in case, here is the code:
@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 selection  *
ECHO *     as suggested by Nicolas Robidoux. *
ECHO *                                       *
ECHO * Authors: Bart van der Wolf,           *
ECHO *          Nicolas Robidoux             *
ECHO *                                       *
ECHO * Suggestions for code optimization:    *
ECHO *   Alan Gibson, Fred Weinhaus          *
ECHO *                                       *
ECHO * Version: alt1                         *
ECHO * Date   : 2014.09.30                   *
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 1.25 -define convolve:scale=^%sharpAmount%%%,100 ^
 -morphology Convolve DoG:3,0,0.4806768770037563 -gamma 0.8 ) ^
 -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
Logged

JRSmit

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 922
    • Jan R. Smit Fine Art Printing Specialist
Re: A free high quality resampling tool for ImageMagick users
« Reply #338 on: September 30, 2014, 11:31:26 am »

I added the batch script as an external editor in LR5.6 and that works. You still have to add the new ima ge to the catalog via synchronise folder f.i.

I am now testing to see if uprezzing with this tool gives better results for printing than the uprezzing of the print function in LR. I am playing with different quality images.
Looking at the histogram, there is little difference, also the softproofing shows practically the same oog areas. Also visually on screen there is no directly visible change in lightness etc.
I did a few testprints. So  far little visible quality gain if any, perhaps a bit snappier is one case.

Advantage though is that you can fine tune the uprezzed image. This is definitely an advantage that can be worthwhile. One of the images tested is a rather noisy image, and by applying all corrections except full capture sharpening, but with good noice reduction. Then sharpening completed after uprezzing, gave a better result. Not by much, but visible.

Will post more detailed findings when done.

Logged
Fine art photography: janrsmit.com
Fine Art Printing Specialist: www.fineartprintingspecialist.nl


Jan R. Smit

Cem

  • Full Member
  • ***
  • Offline Offline
  • Posts: 126
    • Photographs
Re: A free high quality resampling tool for ImageMagick users
« Reply #339 on: September 30, 2014, 12:05:27 pm »

I added the batch script as an external editor in LR5.6 and that works. You still have to add the new ima ge to the catalog via synchronise folder f.i.

Hi Jan,

This is a great idea. It can be further improved by skipping the re-import/synchronize step as follows:

1) Search the text "%~dpn1_%mSize%%~x1" in the bat file (occurs multiple times) and replace all of them with "%~dpn1%~x1".

2) Afterwards, when processing a file from within LR, just select to "edit a copy" (instead of the original in case it is a tif or jpg file).

3) This will create a new file using your chosen rename scheme and the output file from the bat process will just override the copy file. LR will then display the end result without having to re-import or synchronize.

Hope this help. :)
Logged
Pages: 1 ... 15 16 [17] 18 19 ... 24   Go Up